From fed8ecdaafc60eed080bd2b2add9e8302c2bc4c7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 7 Feb 2025 15:59:45 +1100 Subject: [PATCH] Fix use of MEM_callocN for a struct containing a PointerRNA --- .../blender/editors/space_buttons/buttons_ops.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/blender/editors/space_buttons/buttons_ops.cc b/source/blender/editors/space_buttons/buttons_ops.cc index 5a9b0f619dd..fc20bd805c6 100644 --- a/source/blender/editors/space_buttons/buttons_ops.cc +++ b/source/blender/editors/space_buttons/buttons_ops.cc @@ -170,9 +170,9 @@ void BUTTONS_OT_context_menu(wmOperatorType *ot) struct FileBrowseOp { PointerRNA ptr; - PropertyRNA *prop; - bool is_undo; - bool is_userdef; + PropertyRNA *prop = nullptr; + bool is_undo = false; + bool is_userdef = false; }; static int file_browse_exec(bContext *C, wmOperator *op) @@ -245,14 +245,16 @@ static int file_browse_exec(bContext *C, wmOperator *op) U.runtime.is_dirty = true; } - MEM_freeN(op->customdata); + BLI_assert(fbo == op->customdata); + MEM_delete(fbo); return OPERATOR_FINISHED; } static void file_browse_cancel(bContext * /*C*/, wmOperator *op) { - MEM_freeN(op->customdata); + FileBrowseOp *fbo = static_cast(op->customdata); + MEM_delete(fbo); op->customdata = nullptr; } @@ -262,7 +264,6 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event) PropertyRNA *prop; bool is_undo; bool is_userdef; - FileBrowseOp *fbo; char *path; const SpaceFile *sfile = CTX_wm_space_file(C); @@ -318,7 +319,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event) PropertyRNA *prop_relpath; const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath"; - fbo = static_cast(MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp")); + FileBrowseOp *fbo = MEM_new(__func__); fbo->ptr = ptr; fbo->prop = prop; fbo->is_undo = is_undo;