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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user