]> git.mdlowis.com Git - proto/labwc.git/commitdiff
rcxml.c: fix mem leak when deduplicating keybinds
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Fri, 15 Nov 2024 21:58:44 +0000 (22:58 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 16 Nov 2024 22:13:17 +0000 (22:13 +0000)
Before this patch `keybind->keysyms` wasn't free'd when
- deduplicating keybinds
- removing keybinds due to empty action list

This patch creates a shared `keybind_destroy()` helper
which gets used in all cases where a keybind is destroyed.

include/config/keybind.h
src/config/keybind.c
src/config/rcxml.c

index 36d81373731a48d01eee8d5c775ccd8ccfca0563..386839eeb144946112dd74629ed5cffd91702ef4 100644 (file)
@@ -30,6 +30,8 @@ struct keybind {
  */
 struct keybind *keybind_create(const char *keybind);
 
+void keybind_destroy(struct keybind *keybind);
+
 /**
  * parse_modifier - parse a string containing a single modifier name (e.g. "S")
  * into the represented modifier value. returns 0 for invalid modifier names.
index 3370c09ddc441b9dd89a35f9fd6f893b34c6324d..5e5002f76f3c08ae41d1053d767c538072c83d95 100644 (file)
@@ -188,3 +188,12 @@ keybind_create(const char *keybind)
        wl_list_init(&k->actions);
        return k;
 }
+
+void
+keybind_destroy(struct keybind *keybind)
+{
+       assert(wl_list_empty(&keybind->actions));
+
+       zfree(keybind->keysyms);
+       zfree(keybind);
+}
index 3951c72fbc13d522d1b9eeaa7e3cd36475e36007..ce77c8c0a5ca5f9ac43c666f2ea328f9173d4948 100644 (file)
@@ -1626,7 +1626,7 @@ deduplicate_key_bindings(void)
                        if (keybind_the_same(existing, current)) {
                                wl_list_remove(&existing->link);
                                action_list_free(&existing->actions);
-                               free(existing);
+                               keybind_destroy(existing);
                                replaced++;
                                break;
                        }
@@ -1635,7 +1635,7 @@ deduplicate_key_bindings(void)
        wl_list_for_each_safe(current, tmp, &rc.keybinds, link) {
                if (wl_list_empty(&current->actions)) {
                        wl_list_remove(&current->link);
-                       free(current);
+                       keybind_destroy(current);
                        cleared++;
                }
        }
@@ -1948,8 +1948,7 @@ rcxml_finish(void)
        wl_list_for_each_safe(k, k_tmp, &rc.keybinds, link) {
                wl_list_remove(&k->link);
                action_list_free(&k->actions);
-               zfree(k->keysyms);
-               zfree(k);
+               keybind_destroy(k);
        }
 
        struct mousebind *m, *m_tmp;