fix for WM_keymap_remove_item() writing to freed memory.
[blender.git] / source / blender / windowmanager / intern / wm_keymap.c
index 2781ec2d3df85c57168d224509945b438e88f171..3739462ac2cc20eef2b26ff86b29d1135b5c6a55 100644 (file)
@@ -101,11 +101,8 @@ static int wm_keymap_item_equals_result(wmKeyMapItem *a, wmKeyMapItem *b)
        if (strcmp(a->idname, b->idname) != 0)
                return 0;
        
-       if (!((a->ptr == NULL && b->ptr == NULL) ||
-             (a->ptr && b->ptr && IDP_EqualsProperties(a->ptr->data, b->ptr->data))))
-       {
+       if (!RNA_struct_equals(a->ptr, b->ptr))
                return 0;
-       }
        
        if ((a->flag & KMI_INACTIVE) != (b->flag & KMI_INACTIVE))
                return 0;
@@ -190,9 +187,9 @@ wmKeyConfig *WM_keyconfig_new_user(wmWindowManager *wm, const char *idname)
        return keyconf;
 }
 
-void WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf)
+int WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf)
 {
-       if (keyconf) {
+       if (BLI_findindex(&wm->keyconfigs, keyconf) != -1) {
                if (strncmp(U.keyconfigstr, keyconf->idname, sizeof(U.keyconfigstr)) == 0) {
                        BLI_strncpy(U.keyconfigstr, wm->defaultconf->idname, sizeof(U.keyconfigstr));
                        WM_keyconfig_update_tag(NULL, NULL);
@@ -200,6 +197,11 @@ void WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf)
 
                BLI_remlink(&wm->keyconfigs, keyconf);
                WM_keyconfig_free(keyconf);
+
+               return TRUE;
+       }
+       else {
+               return FALSE;
        }
 }
 
@@ -381,7 +383,7 @@ wmKeyMapItem *WM_keymap_add_menu(wmKeyMap *keymap, const char *idname, int type,
        return kmi;
 }
 
-void WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
+int WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
 {
        if (BLI_findindex(&keymap->items, kmi) != -1) {
                if (kmi->ptr) {
@@ -390,7 +392,11 @@ void WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi)
                }
                BLI_freelinkN(&keymap->items, kmi);
 
-               WM_keyconfig_update_tag(keymap, kmi);
+               WM_keyconfig_update_tag(keymap, NULL);
+               return TRUE;
+       }
+       else {
+               return FALSE;
        }
 }
 
@@ -536,7 +542,7 @@ static wmKeyMap *wm_keymap_patch_update(ListBase *lb, wmKeyMap *defaultmap, wmKe
 
        /* copy new keymap from an existing one */
        if (usermap && !(usermap->flag & KEYMAP_DIFF)) {
-               /* for compatibiltiy with old user preferences with non-diff
+               /* for compatibility with old user preferences with non-diff
                 * keymaps we override the original entirely */
                wmKeyMapItem *kmi, *orig_kmi;