mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
Add zfree
This commit is contained in:
parent
1b263e1f67
commit
9f61a819fc
4 changed files with 27 additions and 15 deletions
8
include/common/zfree.h
Normal file
8
include/common/zfree.h
Normal file
|
|
@ -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 */
|
||||
|
|
@ -7,4 +7,5 @@ labwc_sources += files(
|
|||
'nodename.c',
|
||||
'spawn.c',
|
||||
'string-helpers.c',
|
||||
'zfree.c',
|
||||
)
|
||||
|
|
|
|||
11
src/common/zfree.c
Normal file
11
src/common/zfree.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdlib.h>
|
||||
#include "common/zfree.h"
|
||||
|
||||
void __zfree(void **ptr)
|
||||
{
|
||||
if (!ptr || !*ptr) {
|
||||
return;
|
||||
}
|
||||
free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue