1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-14 11:33:14 +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)
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

View File

@ -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);
}

View File

@ -31,8 +31,6 @@
#include <string.h>
#include <mutex>
#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)

View File

@ -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));
}

View File

@ -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. */

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)
{
if (obj->data.opaque) {
free(obj->data.opaque);
obj->data.opaque = NULL;
}
free_and_zero(obj->data.opaque);
}