diff --git a/src/mail.cc b/src/mail.cc index 21ae7ddc..c1a76422 100644 --- a/src/mail.cc +++ b/src/mail.cc @@ -407,10 +407,8 @@ void free_local_mails(struct text_object *obj) if (!locmail) return; - if (locmail->mbox) - free(locmail->mbox); - free(obj->data.opaque); - obj->data.opaque = 0; + free_and_zero(locmail->mbox); + free_and_zero(obj->data.opaque); } #define MAXDATASIZE 1000 diff --git a/src/mboxscan.cc b/src/mboxscan.cc index 5415d85c..1aff91e6 100644 --- a/src/mboxscan.cc +++ b/src/mboxscan.cc @@ -411,11 +411,8 @@ void free_mboxscan(struct text_object *obj) if (!msd) return; - if (msd->args) - free(msd->args); - if (msd->output) - free(msd->output); - free(obj->data.opaque); - obj->data.opaque = NULL; + free_and_zero(msd->args); + free_and_zero(msd->output); + free_and_zero(obj->data.opaque); } diff --git a/src/moc.cc b/src/moc.cc index 09464894..157d67ba 100644 --- a/src/moc.cc +++ b/src/moc.cc @@ -31,8 +31,6 @@ #include #include -#define xfree(x) if (x) free(x); x = 0 - static struct { char *state; char *file; @@ -52,17 +50,17 @@ static timed_thread_ptr moc_thread; void free_moc(struct text_object *obj) { (void)obj; - xfree(moc.state); - xfree(moc.file); - xfree(moc.title); - xfree(moc.artist); - xfree(moc.song); - xfree(moc.album); - xfree(moc.totaltime); - xfree(moc.timeleft); - xfree(moc.curtime); - xfree(moc.bitrate); - xfree(moc.rate); + free_and_zero(moc.state); + free_and_zero(moc.file); + free_and_zero(moc.title); + free_and_zero(moc.artist); + free_and_zero(moc.song); + free_and_zero(moc.album); + free_and_zero(moc.totaltime); + free_and_zero(moc.timeleft); + free_and_zero(moc.curtime); + free_and_zero(moc.bitrate); + free_and_zero(moc.rate); } static void update_infos(void) diff --git a/src/mpd.cc b/src/mpd.cc index 40cf51f2..cddc8911 100644 --- a/src/mpd.cc +++ b/src/mpd.cc @@ -105,17 +105,15 @@ void init_mpd(void) static void clear_mpd(void) { -#define xfree(x) if (x) free(x) - xfree(mpd_info.title); - xfree(mpd_info.artist); - xfree(mpd_info.album); + free_and_zero(mpd_info.title); + free_and_zero(mpd_info.artist); + free_and_zero(mpd_info.album); /* do not free() the const char *status! */ /* do not free() the const char *random! */ /* do not free() the const char *repeat! */ - xfree(mpd_info.track); - xfree(mpd_info.name); - xfree(mpd_info.file); -#undef xfree + free_and_zero(mpd_info.track); + free_and_zero(mpd_info.name); + free_and_zero(mpd_info.file); memset(&mpd_info, 0, sizeof(mpd_info)); } diff --git a/src/net_stat.cc b/src/net_stat.cc index 38bfcd61..28308886 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -313,9 +313,7 @@ void clear_net_stats(void) { int i; for (i = 0; i < MAX_NET_INTERFACES; i++) { - if (netstats[i].dev) { - free(netstats[i].dev); - } + free_and_zero(netstats[i].dev); } memset(netstats, 0, sizeof(netstats)); } @@ -327,10 +325,7 @@ void parse_if_up_arg(struct text_object *obj, const char *arg) void free_if_up(struct text_object *obj) { - if (obj->data.opaque) { - free(obj->data.opaque); - obj->data.opaque = NULL; - } + free_and_zero(obj->data.opaque); } /* We should check if this is ok with OpenBSD and NetBSD as well. */ diff --git a/src/nvidia.cc b/src/nvidia.cc index 59866782..62473428 100644 --- a/src/nvidia.cc +++ b/src/nvidia.cc @@ -128,9 +128,6 @@ void print_nvidia_value(struct text_object *obj, char *p, int p_max_size) void free_nvidia(struct text_object *obj) { - if (obj->data.opaque) { - free(obj->data.opaque); - obj->data.opaque = NULL; - } + free_and_zero(obj->data.opaque); }