From b77c449c5eb0d244bd0367746ce45da07b89e38a Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 1 Dec 2018 11:41:54 +0100 Subject: [PATCH] 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. --- src/editor.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; -- 2.34.1