Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-01-22 02:42:09 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-22 02:42:09 +0400
commit83b1f21cf9454cbbe49411b8973d57b5c9f76642 (patch)
tree2c7a141bff4b800d49d6b729cc13de897c4d6330 /source/blender/editors/interface
parentb95beea539b22baeb68013c4e65fb0455b968890 (diff)
fix for memory leak displaying shortcuts to buttons which use allocated string, also de-duplocate this code which had this error in 2 places.
noticed while testing 1023 length paths.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c50
-rw-r--r--source/blender/editors/interface/interface_handlers.c22
-rw-r--r--source/blender/editors/interface/interface_intern.h1
3 files changed, 41 insertions, 32 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index c112918833e..3a1bab9987e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -800,11 +800,43 @@ static void ui_menu_block_set_keyaccels(uiBlock *block)
}
}
+/* XXX, this code will shorten any allocated string to 'UI_MAX_NAME_STR'
+ * since this is really long its unlikely to be an issue,
+ * but this could be supported */
+void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const short do_strip)
+{
+
+ if (do_strip) {
+ char *cpoin= strchr(but->str, '|');
+ if(cpoin) {
+ *cpoin= '\0';
+ }
+ }
+
+ /* without this, just allow stripping of the shortcut */
+ if (shortcut_str) {
+ char *butstr_orig;
+
+ if (but->str != but->strdata) {
+ butstr_orig = but->str; /* free after using as source buffer */
+ }
+ else {
+ butstr_orig = BLI_strdup(but->str);
+ }
+ BLI_snprintf(but->strdata,
+ sizeof(but->strdata),
+ "%s|%s",
+ butstr_orig, shortcut_str);
+ MEM_freeN(butstr_orig);
+ but->str = but->strdata;
+ ui_check_but(but);
+ }
+}
static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
{
uiBut *but;
- char buf[512];
+ char buf[128];
/* for menu's */
MenuType *mt;
@@ -815,18 +847,6 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
if(block->minx != block->maxx)
return;
-
-#define UI_MENU_KEY_STR_CAT \
- char *butstr_orig= BLI_strdup(but->str); \
- BLI_snprintf(but->strdata, \
- sizeof(but->strdata), \
- "%s|%s", \
- butstr_orig, buf); \
- MEM_freeN(butstr_orig); \
- but->str= but->strdata; \
- ui_check_but(but); \
-
-
for(but=block->buttons.first; but; but=but->next) {
if(but->optype) {
IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
@@ -834,7 +854,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, TRUE,
buf, sizeof(buf)))
{
- UI_MENU_KEY_STR_CAT
+ ui_but_add_shortcut(but, buf, FALSE);
}
}
else if ((mt= uiButGetMenuType(but))) {
@@ -851,7 +871,7 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
if(WM_key_event_operator_string(C, "WM_OT_call_menu", WM_OP_INVOKE_REGION_WIN, prop_menu, FALSE,
buf, sizeof(buf)))
{
- UI_MENU_KEY_STR_CAT
+ ui_but_add_shortcut(but, buf, FALSE);
}
}
}
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 311f0f87b50..93d8f9c0c8a 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -4382,31 +4382,19 @@ static void but_shortcut_name_func(bContext *C, void *arg1, int UNUSED(event))
uiBut *but = (uiBut *)arg1;
if (but->optype) {
- char buf[512], *cpoin;
+ char shortcut_str[128];
IDProperty *prop= (but->opptr)? but->opptr->data: NULL;
/* complex code to change name of button */
if(WM_key_event_operator_string(C, but->optype->idname, but->opcontext, prop, TRUE,
- buf, sizeof(buf)))
+ shortcut_str, sizeof(shortcut_str)))
{
- char *butstr_orig;
-
- // XXX but->str changed... should not, remove the hotkey from it
- cpoin= strchr(but->str, '|');
- if(cpoin) *cpoin= 0;
-
- butstr_orig= BLI_strdup(but->str);
- BLI_snprintf(but->strdata, sizeof(but->strdata), "%s|%s", butstr_orig, buf);
- MEM_freeN(butstr_orig);
- but->str= but->strdata;
-
- ui_check_but(but);
+ ui_but_add_shortcut(but, shortcut_str, TRUE);
}
else {
- /* shortcut was removed */
- cpoin= strchr(but->str, '|');
- if(cpoin) *cpoin= 0;
+ /* simply strip the shortcut */
+ ui_but_add_shortcut(but, NULL, TRUE);
}
}
}
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 2980b28d522..2d8de475c4b 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -498,6 +498,7 @@ void ui_resources_free(void);
void ui_layout_add_but(uiLayout *layout, uiBut *but);
int ui_but_can_align(uiBut *but);
void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop);
+void ui_but_add_shortcut(uiBut *but, const char *key_str, const short do_strip);
/* interface_anim.c */
void ui_but_anim_flag(uiBut *but, float cfra);