]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add zfree
authorJohan Malm <jgm323@gmail.com>
Sun, 21 Feb 2021 21:59:53 +0000 (21:59 +0000)
committerJohan Malm <jgm323@gmail.com>
Sun, 21 Feb 2021 21:59:53 +0000 (21:59 +0000)
include/common/zfree.h [new file with mode: 0644]
src/common/meson.build
src/common/zfree.c [new file with mode: 0644]
src/config/rcxml.c

diff --git a/include/common/zfree.h b/include/common/zfree.h
new file mode 100644 (file)
index 0000000..e791b68
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __LABWC_ZFREE_H
+#define __LABWC_ZFREE_H
+
+void __zfree(void **ptr);
+
+#define zfree(ptr) __zfree((void **)&(ptr))
+
+#endif /* __LABWC_ZFREE_H */
index 3efd27b41bf9ea4b63420704fa7f926bcbcf2c9d..21044fdb2bb99dd0ee1bd7331749566cf9589292 100644 (file)
@@ -7,4 +7,5 @@ labwc_sources += files(
   'nodename.c',
   'spawn.c',
   'string-helpers.c',
+  'zfree.c',
 )
diff --git a/src/common/zfree.c b/src/common/zfree.c
new file mode 100644 (file)
index 0000000..106a628
--- /dev/null
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+#include "common/zfree.h"
+
+void __zfree(void **ptr)
+{
+       if (!ptr || !*ptr) {
+               return;
+       }
+       free(*ptr);
+       *ptr = NULL;
+}
index 835b24aecdb5e15497106746062fa2d1e3a62ecf..c308f97a77d52b2096affa3e4578515f6cc455ee 100644 (file)
@@ -16,6 +16,7 @@
 #include "common/log.h"
 #include "common/nodename.h"
 #include "common/string-helpers.h"
+#include "common/zfree.h"
 #include "config/keybind.h"
 #include "config/rcxml.h"
 
@@ -340,28 +341,19 @@ no_config:
        post_processing();
 }
 
-static void
-free_safe(const void *p)
-{
-       if (p) {
-               free((void *)p);
-       }
-       p = NULL;
-}
-
 void
 rcxml_finish(void)
 {
-       free_safe(rc.font_name_activewindow);
-       free_safe(rc.theme_name);
+       zfree(rc.font_name_activewindow);
+       zfree(rc.theme_name);
 
        struct keybind *k, *k_tmp;
        wl_list_for_each_safe (k, k_tmp, &rc.keybinds, link) {
                wl_list_remove(&k->link);
-               free_safe(k->command);
-               free_safe(k->action);
-               free_safe(k->keysyms);
-               free_safe(k);
+               zfree(k->command);
+               zfree(k->action);
+               zfree(k->keysyms);
+               zfree(k);
        }
 }