1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

Use free_and_zero in l*.cc where appropriate

This commit is contained in:
Nikolas Garofil 2010-02-24 01:51:02 +01:00
parent a2110d44d7
commit 1fa465efb6
3 changed files with 28 additions and 77 deletions

View File

@ -485,12 +485,8 @@ void mpd_clearError(mpd_Connection *connection)
void mpd_closeConnection(mpd_Connection *connection) void mpd_closeConnection(mpd_Connection *connection)
{ {
closesocket(connection->sock); closesocket(connection->sock);
if (connection->returnElement) { free_and_zero(connection->returnElement);
free(connection->returnElement); free_and_zero(connection->request);
}
if (connection->request) {
free(connection->request);
}
free(connection); free(connection);
WSACleanup(); WSACleanup();
} }
@ -856,9 +852,7 @@ mpd_Status *mpd_getStatus(mpd_Connection *connection)
void mpd_freeStatus(mpd_Status *status) void mpd_freeStatus(mpd_Status *status)
{ {
if (status->error) { free_and_zero(status->error);
free(status->error);
}
free(status); free(status);
} }
@ -1011,39 +1005,17 @@ static void mpd_initSong(mpd_Song *song)
static void mpd_finishSong(mpd_Song *song) static void mpd_finishSong(mpd_Song *song)
{ {
if (song->file) { free_and_zero(song->file);
free(song->file); free_and_zero(song->artist);
} free_and_zero(song->album);
if (song->artist) { free_and_zero(song->title);
free(song->artist); free_and_zero(song->track);
} free_and_zero(song->name);
if (song->album) { free_and_zero(song->date);
free(song->album); free_and_zero(song->genre);
} free_and_zero(song->composer);
if (song->title) { free_and_zero(song->disc);
free(song->title); free_and_zero(song->comment);
}
if (song->track) {
free(song->track);
}
if (song->name) {
free(song->name);
}
if (song->date) {
free(song->date);
}
if (song->genre) {
free(song->genre);
}
if (song->composer) {
free(song->composer);
}
if (song->disc) {
free(song->disc);
}
if (song->comment) {
free(song->comment);
}
} }
mpd_Song *mpd_newSong(void) mpd_Song *mpd_newSong(void)
@ -1112,9 +1084,7 @@ static void mpd_initDirectory(mpd_Directory *directory)
static void mpd_finishDirectory(mpd_Directory *directory) static void mpd_finishDirectory(mpd_Directory *directory)
{ {
if (directory->path) { free_and_zero(directory->path);
free(directory->path);
}
} }
mpd_Directory *mpd_newDirectory(void) mpd_Directory *mpd_newDirectory(void)
@ -1151,9 +1121,7 @@ static void mpd_initPlaylistFile(mpd_PlaylistFile *playlist)
static void mpd_finishPlaylistFile(mpd_PlaylistFile *playlist) static void mpd_finishPlaylistFile(mpd_PlaylistFile *playlist)
{ {
if (playlist->path) { free_and_zero(playlist->path);
free(playlist->path);
}
} }
mpd_PlaylistFile *mpd_newPlaylistFile(void) mpd_PlaylistFile *mpd_newPlaylistFile(void)
@ -2084,8 +2052,7 @@ void mpd_commitSearch(mpd_Connection *connection)
connection->request[len - 1] = '\0'; connection->request[len - 1] = '\0';
mpd_sendInfoCommand(connection, connection->request); mpd_sendInfoCommand(connection, connection->request);
free(connection->request); free_and_zero(connection->request);
connection->request = NULL;
} }
/** /**

View File

@ -248,7 +248,6 @@ static struct {
int count; int count;
} gw_info; } gw_info;
#define COND_FREE(x) if(x) free(x); x = 0
#define SAVE_SET_STRING(x, y) \ #define SAVE_SET_STRING(x, y) \
if (x && strcmp((char *)x, (char *)y)) { \ if (x && strcmp((char *)x, (char *)y)) { \
free(x); \ free(x); \
@ -279,8 +278,8 @@ void update_gateway_info(void)
unsigned long dest, gate, mask; unsigned long dest, gate, mask;
unsigned int flags; unsigned int flags;
COND_FREE(gw_info.iface); free_and_zero(gw_info.iface);
COND_FREE(gw_info.ip); free_and_zero(gw_info.ip);
gw_info.count = 0; gw_info.count = 0;
if ((fp = fopen("/proc/net/route", "r")) == NULL) { if ((fp = fopen("/proc/net/route", "r")) == NULL) {
@ -315,10 +314,8 @@ void free_gateway_info(struct text_object *obj)
{ {
(void)obj; (void)obj;
if (gw_info.iface) free_and_zero(gw_info.iface);
free(gw_info.iface); free_and_zero(gw_info.ip);
if (gw_info.ip)
free(gw_info.ip);
memset(&gw_info, 0, sizeof(gw_info)); memset(&gw_info, 0, sizeof(gw_info));
} }
@ -1116,8 +1113,7 @@ void free_sysfs_sensor(struct text_object *obj)
return; return;
close(sf->fd); close(sf->fd);
free(obj->data.opaque); free_and_zero(obj->data.opaque);
obj->data.opaque = NULL;
} }
#define CPUFREQ_PREFIX "/sys/devices/system/cpu" #define CPUFREQ_PREFIX "/sys/devices/system/cpu"

View File

@ -299,22 +299,10 @@ void llua_close(void)
#ifdef HAVE_SYS_INOTIFY_H #ifdef HAVE_SYS_INOTIFY_H
llua_rm_notifies(); llua_rm_notifies();
#endif /* HAVE_SYS_INOTIFY_H */ #endif /* HAVE_SYS_INOTIFY_H */
if (draw_pre_hook) { free_and_zero(draw_pre_hook);
free(draw_pre_hook); free_and_zero(draw_post_hook);
draw_pre_hook = 0; free_and_zero(startup_hook);
} free_and_zero(shutdown_hook);
if (draw_post_hook) {
free(draw_post_hook);
draw_post_hook = 0;
}
if (startup_hook) {
free(startup_hook);
startup_hook = 0;
}
if (shutdown_hook) {
free(shutdown_hook);
shutdown_hook = 0;
}
if(!lua_L) return; if(!lua_L) return;
lua_close(lua_L); lua_close(lua_L);
lua_L = NULL; lua_L = NULL;
@ -410,13 +398,13 @@ void llua_set_number(const char *key, double value)
void llua_set_startup_hook(const char *args) void llua_set_startup_hook(const char *args)
{ {
if (startup_hook) free(startup_hook); free_and_zero(startup_hook);
startup_hook = strdup(args); startup_hook = strdup(args);
} }
void llua_set_shutdown_hook(const char *args) void llua_set_shutdown_hook(const char *args)
{ {
if (shutdown_hook) free(shutdown_hook); free_and_zero(shutdown_hook);
shutdown_hook = strdup(args); shutdown_hook = strdup(args);
} }