Commit: 664e854af7fa2c4ba6ee81559256f08096f84165
Author: Julian Eisel
Date:   Thu Jun 2 20:19:56 2016 +1000
Branches: master
https://developer.blender.org/rB664e854af7fa2c4ba6ee81559256f08096f84165

Fix leak using UI_BTYPE_TEXT button w/o a callback

Moving ownership of the string to the button's 'rename_orig'
leaked when the button didn't have a uiAfterFunc.

===================================================================

M       source/blender/editors/interface/interface_handlers.c

===================================================================

diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index 10ab85a..5b8b8ae 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -634,6 +634,15 @@ PointerRNA 
*ui_handle_afterfunc_add_operator(wmOperatorType *ot, int opcontext,
        return ptr;
 }
 
+/**
+ * Check if a #uiAfterFunc is needed for this button.
+ */
+static bool ui_afterfunc_check(const uiBlock *block, const uiBut *but)
+{
+       return (but->func || but->funcN || but->rename_func || but->optype || 
but->rnaprop || block->handle_func ||
+               (but->type == UI_BTYPE_BUT_MENU && block->butm_func));
+}
+
 static void ui_apply_but_func(bContext *C, uiBut *but)
 {
        uiAfterFunc *after;
@@ -643,9 +652,7 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
         * handling is done, i.e. menus are closed, in order to avoid conflicts
         * with these functions removing the buttons we are working with */
 
-       if (but->func || but->funcN || block->handle_func || but->rename_func ||
-           (but->type == UI_BTYPE_BUT_MENU && block->butm_func) || but->optype 
|| but->rnaprop)
-       {
+       if (ui_afterfunc_check(block, but)) {
                after = ui_afterfunc_new();
 
                if (but->func && ELEM(but, but->func_arg1, but->func_arg2)) {
@@ -899,7 +906,8 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, 
uiHandleButtonData *data)
                 * having typed something already. */
                but->rename_orig = BLI_strdup(data->origstr);
        }
-       else {
+       /* only if there are afterfuncs, otherwise 'renam_orig' isn't freed */
+       else if (ui_afterfunc_check(but->block, but)) {
                but->rename_orig = data->origstr;
                data->origstr = NULL;
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to