diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2016-06-02 13:19:56 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-06-02 13:31:48 +0300 |
commit | 664e854af7fa2c4ba6ee81559256f08096f84165 (patch) | |
tree | 832122a9bc43a404c44320c96376e8ad62195ef9 /source | |
parent | 64663b1f736eb0ac234200d74a9e3a78273d939f (diff) |
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 10ab85a6142..5b8b8ae5bdb 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; } |