From: Holger Schemel Date: Sat, 1 Dec 2018 10:41:54 +0000 (+0100) Subject: fixed potential crash bug with empty (padding) element buttons in editor X-Git-Tag: 4.1.2.0~89 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=b77c449c5eb0d244bd0367746ce45da07b89e38a;hp=6229b51a03a4113fa799587e0f58fcea0f634d41 fixed potential crash bug with empty (padding) element buttons in editor This fixes a bug that can cause a crash when accessing memory that was already free()'ed again, because the variable that contains the amount of allocated memory is not updated when memory allocation changes. The bug is fixed by updating that variable when memory is allocated. --- diff --git a/src/editor.c b/src/editor.c index 33e9dae5..9396d5ef 100644 --- a/src/editor.c +++ b/src/editor.c @@ -7146,7 +7146,10 @@ void CreateLevelEditorGadgets(void) right_gadget_border = checked_calloc(num_editor_gadgets * sizeof(int)); - editor_el_empty = checked_calloc(ED_NUM_ELEMENTLIST_BUTTONS * sizeof(int)); + // set number of empty (padding) element buttons to maximum number of buttons + num_editor_el_empty = ED_NUM_ELEMENTLIST_BUTTONS; + + editor_el_empty = checked_calloc(num_editor_el_empty * sizeof(int)); editor_el_empty_ptr = editor_el_empty; use_permanent_palette = !editor.palette.show_as_separate_screen;