From cf5fc4dcec4e73d892844b1d3766a70149f06004 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 21 Apr 2025 17:21:43 +0200 Subject: [PATCH] Fix: Mismatched new/delete in annotation and text operators Pull Request: https://projects.blender.org/blender/blender/pulls/137404 --- .../editors/gpencil_legacy/annotate_paint.cc | 19 ++++++++----------- source/blender/editors/space_text/text_ops.cc | 14 ++++++-------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/source/blender/editors/gpencil_legacy/annotate_paint.cc b/source/blender/editors/gpencil_legacy/annotate_paint.cc index 148621d03a4..fa31190369b 100644 --- a/source/blender/editors/gpencil_legacy/annotate_paint.cc +++ b/source/blender/editors/gpencil_legacy/annotate_paint.cc @@ -2189,18 +2189,17 @@ static void annotation_draw_apply_event( /* operator 'redo' (i.e. after changing some properties, but also for repeat last) */ static wmOperatorStatus annotation_draw_exec(bContext *C, wmOperator *op) { - tGPsdata *p = nullptr; Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); /* try to initialize context data needed while drawing */ if (!annotation_draw_init(C, op, nullptr)) { - if (op->customdata) { - MEM_freeN(op->customdata); - } + tGPsdata *p = static_cast(op->customdata); + MEM_delete(p); + op->customdata = nullptr; return OPERATOR_CANCELLED; } - p = static_cast(op->customdata); + tGPsdata *p = static_cast(op->customdata); /* loop over the stroke RNA elements recorded (i.e. progress of mouse movement), * setting the relevant values in context at each step, then applying @@ -2256,8 +2255,6 @@ static wmOperatorStatus annotation_draw_exec(bContext *C, wmOperator *op) /* start of interactive drawing part of operator */ static wmOperatorStatus annotation_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - tGPsdata *p = nullptr; - /* support for tablets eraser pen */ if (annotation_is_tablet_eraser_active(event)) { RNA_enum_set(op->ptr, "mode", GP_PAINTMODE_ERASER); @@ -2265,13 +2262,13 @@ static wmOperatorStatus annotation_draw_invoke(bContext *C, wmOperator *op, cons /* try to initialize context data needed while drawing */ if (!annotation_draw_init(C, op, event)) { - if (op->customdata) { - MEM_freeN(op->customdata); - } + tGPsdata *p = static_cast(op->customdata); + MEM_delete(p); + op->customdata = nullptr; return OPERATOR_CANCELLED; } - p = static_cast(op->customdata); + tGPsdata *p = static_cast(op->customdata); /* if empty erase capture and finish */ if (p->status == GP_STATUS_CAPTURE) { diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc index 154af2e422e..2317a4be98f 100644 --- a/source/blender/editors/space_text/text_ops.cc +++ b/source/blender/editors/space_text/text_ops.cc @@ -404,7 +404,6 @@ static wmOperatorStatus text_open_exec(bContext *C, wmOperator *op) SpaceText *st = CTX_wm_space_text(C); Main *bmain = CTX_data_main(C); Text *text; - PropertyPointerRNA *pprop; char filepath[FILE_MAX]; const bool internal = RNA_boolean_get(op->ptr, "internal"); @@ -412,20 +411,18 @@ static wmOperatorStatus text_open_exec(bContext *C, wmOperator *op) text = BKE_text_load_ex(bmain, filepath, BKE_main_blendfile_path(bmain), internal); + PropertyPointerRNA *pprop = static_cast(op->customdata); if (!text) { - if (op->customdata) { - MEM_freeN(op->customdata); - } + MEM_delete(pprop); + op->customdata = nullptr; return OPERATOR_CANCELLED; } - if (!op->customdata) { + if (!pprop) { text_open_init(C, op); } /* hook into UI */ - pprop = static_cast(op->customdata); - if (pprop->prop) { PointerRNA idptr = RNA_id_pointer_create(&text->id); RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr, nullptr); @@ -2788,7 +2785,8 @@ static void scroll_exit(bContext *C, wmOperator *op) st->runtime->scroll_ofs_px[1] = 0; ED_area_tag_redraw(CTX_wm_area(C)); - MEM_freeN(op->customdata); + MEM_freeN(tsc); + op->customdata = nullptr; } static wmOperatorStatus text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event)