1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-15 03:43:50 +00:00

Use free_and_zero in [m-o]*.cc where appropriate

This commit is contained in:
Nikolas Garofil 2010-02-24 02:14:20 +01:00
parent 1fa465efb6
commit 6092d063c9
6 changed files with 25 additions and 42 deletions

View File

@ -407,10 +407,8 @@ void free_local_mails(struct text_object *obj)
if (!locmail) if (!locmail)
return; return;
if (locmail->mbox) free_and_zero(locmail->mbox);
free(locmail->mbox); free_and_zero(obj->data.opaque);
free(obj->data.opaque);
obj->data.opaque = 0;
} }
#define MAXDATASIZE 1000 #define MAXDATASIZE 1000

View File

@ -411,11 +411,8 @@ void free_mboxscan(struct text_object *obj)
if (!msd) if (!msd)
return; return;
if (msd->args) free_and_zero(msd->args);
free(msd->args); free_and_zero(msd->output);
if (msd->output) free_and_zero(obj->data.opaque);
free(msd->output);
free(obj->data.opaque);
obj->data.opaque = NULL;
} }

View File

@ -31,8 +31,6 @@
#include <string.h> #include <string.h>
#include <mutex> #include <mutex>
#define xfree(x) if (x) free(x); x = 0
static struct { static struct {
char *state; char *state;
char *file; char *file;
@ -52,17 +50,17 @@ static timed_thread_ptr moc_thread;
void free_moc(struct text_object *obj) void free_moc(struct text_object *obj)
{ {
(void)obj; (void)obj;
xfree(moc.state); free_and_zero(moc.state);
xfree(moc.file); free_and_zero(moc.file);
xfree(moc.title); free_and_zero(moc.title);
xfree(moc.artist); free_and_zero(moc.artist);
xfree(moc.song); free_and_zero(moc.song);
xfree(moc.album); free_and_zero(moc.album);
xfree(moc.totaltime); free_and_zero(moc.totaltime);
xfree(moc.timeleft); free_and_zero(moc.timeleft);
xfree(moc.curtime); free_and_zero(moc.curtime);
xfree(moc.bitrate); free_and_zero(moc.bitrate);
xfree(moc.rate); free_and_zero(moc.rate);
} }
static void update_infos(void) static void update_infos(void)

View File

@ -105,17 +105,15 @@ void init_mpd(void)
static void clear_mpd(void) static void clear_mpd(void)
{ {
#define xfree(x) if (x) free(x) free_and_zero(mpd_info.title);
xfree(mpd_info.title); free_and_zero(mpd_info.artist);
xfree(mpd_info.artist); free_and_zero(mpd_info.album);
xfree(mpd_info.album);
/* do not free() the const char *status! */ /* do not free() the const char *status! */
/* do not free() the const char *random! */ /* do not free() the const char *random! */
/* do not free() the const char *repeat! */ /* do not free() the const char *repeat! */
xfree(mpd_info.track); free_and_zero(mpd_info.track);
xfree(mpd_info.name); free_and_zero(mpd_info.name);
xfree(mpd_info.file); free_and_zero(mpd_info.file);
#undef xfree
memset(&mpd_info, 0, sizeof(mpd_info)); memset(&mpd_info, 0, sizeof(mpd_info));
} }

View File

@ -313,9 +313,7 @@ void clear_net_stats(void)
{ {
int i; int i;
for (i = 0; i < MAX_NET_INTERFACES; i++) { for (i = 0; i < MAX_NET_INTERFACES; i++) {
if (netstats[i].dev) { free_and_zero(netstats[i].dev);
free(netstats[i].dev);
}
} }
memset(netstats, 0, sizeof(netstats)); 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) void free_if_up(struct text_object *obj)
{ {
if (obj->data.opaque) { free_and_zero(obj->data.opaque);
free(obj->data.opaque);
obj->data.opaque = NULL;
}
} }
/* We should check if this is ok with OpenBSD and NetBSD as well. */ /* We should check if this is ok with OpenBSD and NetBSD as well. */

View File

@ -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) void free_nvidia(struct text_object *obj)
{ {
if (obj->data.opaque) { free_and_zero(obj->data.opaque);
free(obj->data.opaque);
obj->data.opaque = NULL;
}
} }