mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-29 18:18:39 +00:00
Use free_and_zero in [u-z]*.cc where appropriate
This commit is contained in:
parent
da76381300
commit
c1648e6558
@ -28,6 +28,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "conky.h"
|
||||
#include "config.h"
|
||||
#include "common.h"
|
||||
#include "text_object.h"
|
||||
|
@ -26,6 +26,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include "conky.h"
|
||||
#include "config.h"
|
||||
#include "text_object.h"
|
||||
#include "logging.h"
|
||||
|
63
src/users.cc
63
src/users.cc
@ -141,17 +141,11 @@ static void update_user_time(char *tty)
|
||||
tty_user_time(temp, tty);
|
||||
|
||||
if (temp != NULL) {
|
||||
if (current_info->users.ctime) {
|
||||
free(current_info->users.ctime);
|
||||
current_info->users.ctime = 0;
|
||||
}
|
||||
free_and_zero(current_info->users.ctime);
|
||||
current_info->users.ctime = (char*)malloc(text_buffer_size);
|
||||
strncpy(current_info->users.ctime, temp, text_buffer_size);
|
||||
} else {
|
||||
if (current_info->users.ctime) {
|
||||
free(current_info->users.ctime);
|
||||
current_info->users.ctime = 0;
|
||||
}
|
||||
free_and_zero(current_info->users.ctime);
|
||||
current_info->users.ctime = (char*)malloc(text_buffer_size);
|
||||
strncpy(current_info->users.ctime, "broken", text_buffer_size);
|
||||
}
|
||||
@ -165,17 +159,11 @@ void update_users(void)
|
||||
users_alloc(current_info);
|
||||
user_name(temp);
|
||||
if (temp != NULL) {
|
||||
if (current_info->users.names) {
|
||||
free(current_info->users.names);
|
||||
current_info->users.names = 0;
|
||||
}
|
||||
free_and_zero(current_info->users.names);
|
||||
current_info->users.names = (char*)malloc(text_buffer_size);
|
||||
strncpy(current_info->users.names, temp, text_buffer_size);
|
||||
} else {
|
||||
if (current_info->users.names) {
|
||||
free(current_info->users.names);
|
||||
current_info->users.names = 0;
|
||||
}
|
||||
free_and_zero(current_info->users.names);
|
||||
current_info->users.names = (char*)malloc(text_buffer_size);
|
||||
strncpy(current_info->users.names, "broken", text_buffer_size);
|
||||
}
|
||||
@ -191,33 +179,21 @@ void update_users(void)
|
||||
temp[0] = 0;
|
||||
user_term(temp);
|
||||
if (temp != NULL) {
|
||||
if (current_info->users.terms) {
|
||||
free(current_info->users.terms);
|
||||
current_info->users.terms = 0;
|
||||
}
|
||||
free_and_zero(current_info->users.terms);
|
||||
current_info->users.terms = (char*)malloc(text_buffer_size);
|
||||
strncpy(current_info->users.terms, temp, text_buffer_size);
|
||||
} else {
|
||||
if (current_info->users.terms) {
|
||||
free(current_info->users.terms);
|
||||
current_info->users.terms = 0;
|
||||
}
|
||||
free_and_zero(current_info->users.terms);
|
||||
current_info->users.terms = (char*)malloc(text_buffer_size);
|
||||
strncpy(current_info->users.terms, "broken", text_buffer_size);
|
||||
}
|
||||
user_time(temp);
|
||||
if (temp != NULL) {
|
||||
if (current_info->users.times) {
|
||||
free(current_info->users.times);
|
||||
current_info->users.times = 0;
|
||||
}
|
||||
free_and_zero(current_info->users.times);
|
||||
current_info->users.times = (char*)malloc(text_buffer_size);
|
||||
strncpy(current_info->users.times, temp, text_buffer_size);
|
||||
} else {
|
||||
if (current_info->users.times) {
|
||||
free(current_info->users.times);
|
||||
current_info->users.times = 0;
|
||||
}
|
||||
free_and_zero(current_info->users.times);
|
||||
current_info->users.times = (char*)malloc(text_buffer_size);
|
||||
strncpy(current_info->users.times, "broken", text_buffer_size);
|
||||
}
|
||||
@ -256,36 +232,23 @@ void print_user_number(struct text_object *obj, char *p, int p_max_size)
|
||||
void free_user_names(struct text_object *obj)
|
||||
{
|
||||
(void)obj;
|
||||
if (info.users.names) {
|
||||
free(info.users.names);
|
||||
info.users.names = 0;
|
||||
}
|
||||
free_and_zero(info.users.names);
|
||||
}
|
||||
|
||||
void free_user_terms(struct text_object *obj)
|
||||
{
|
||||
(void)obj;
|
||||
if (info.users.terms) {
|
||||
free(info.users.terms);
|
||||
info.users.terms = 0;
|
||||
}
|
||||
free_and_zero(info.users.terms);
|
||||
}
|
||||
|
||||
void free_user_times(struct text_object *obj)
|
||||
{
|
||||
(void)obj;
|
||||
if (info.users.times) {
|
||||
free(info.users.times);
|
||||
info.users.times = 0;
|
||||
}
|
||||
free_and_zero(info.users.times);
|
||||
}
|
||||
|
||||
void free_user_time(struct text_object *obj)
|
||||
{
|
||||
if (info.users.ctime) {
|
||||
free(info.users.ctime);
|
||||
info.users.ctime = 0;
|
||||
}
|
||||
if (obj->data.s)
|
||||
free(obj->data.s);
|
||||
free_and_zero(info.users.ctime);
|
||||
free_and_zero(obj->data.s);
|
||||
}
|
||||
|
@ -1010,8 +1010,5 @@ void print_weather(struct text_object *obj, char *p, int p_max_size)
|
||||
|
||||
void free_weather(struct text_object *obj)
|
||||
{
|
||||
if (obj->data.opaque) {
|
||||
free(obj->data.opaque);
|
||||
obj->data.opaque = NULL;
|
||||
}
|
||||
free_and_zero(obj->data.opaque);
|
||||
}
|
||||
|
20
src/x11.cc
20
src/x11.cc
@ -698,10 +698,7 @@ static inline void get_x11_desktop_names(Display *current_display, Window root,
|
||||
(actual_type == ATOM(UTF8_STRING)) &&
|
||||
(nitems > 0L) && (actual_format == 8) ) {
|
||||
|
||||
if(current_info->x11.desktop.all_names) {
|
||||
free(current_info->x11.desktop.all_names);
|
||||
current_info->x11.desktop.all_names = NULL;
|
||||
}
|
||||
free_and_zero(current_info->x11.desktop.all_names);
|
||||
current_info->x11.desktop.all_names = (char*)malloc(nitems*sizeof(char));
|
||||
memcpy(current_info->x11.desktop.all_names, prop, nitems);
|
||||
current_info->x11.desktop.nitems = nitems;
|
||||
@ -721,10 +718,7 @@ static inline void get_x11_desktop_current_name(char *names)
|
||||
while ( i < current_info->x11.desktop.nitems ) {
|
||||
if ( names[i++] == '\0' ) {
|
||||
if ( ++k == current_info->x11.desktop.current ) {
|
||||
if (current_info->x11.desktop.name) {
|
||||
free(current_info->x11.desktop.name);
|
||||
current_info->x11.desktop.name = NULL;
|
||||
}
|
||||
free_and_zero(current_info->x11.desktop.name);
|
||||
current_info->x11.desktop.name = (char*)malloc((i-j)*sizeof(char));
|
||||
//desktop names can be empty but should always be not null
|
||||
strcpy( current_info->x11.desktop.name, (char *)&names[j] );
|
||||
@ -834,14 +828,8 @@ void print_desktop_name(struct text_object *obj, char *p, int p_max_size)
|
||||
|
||||
void free_desktop_info(void)
|
||||
{
|
||||
if(info.x11.desktop.name) {
|
||||
free(info.x11.desktop.name);
|
||||
info.x11.desktop.name = NULL;
|
||||
}
|
||||
if(info.x11.desktop.all_names) {
|
||||
free(info.x11.desktop.all_names);
|
||||
info.x11.desktop.all_names = NULL;
|
||||
}
|
||||
free_and_zero(info.x11.desktop.name);
|
||||
free_and_zero(info.x11.desktop.all_names);
|
||||
}
|
||||
|
||||
#ifdef OWN_WINDOW
|
||||
|
19
src/xmms2.cc
19
src/xmms2.cc
@ -84,20 +84,19 @@ static void xmms_alloc(struct information *ptr)
|
||||
ptr->xmms2.timesplayed = -1;
|
||||
}
|
||||
|
||||
#define xfree(x) if (x) { free(x); x = 0; }
|
||||
void free_xmms2(struct text_object *obj)
|
||||
{
|
||||
(void)obj;
|
||||
|
||||
xfree(info.xmms2.artist);
|
||||
xfree(info.xmms2.album);
|
||||
xfree(info.xmms2.title);
|
||||
xfree(info.xmms2.genre);
|
||||
xfree(info.xmms2.comment);
|
||||
xfree(info.xmms2.url);
|
||||
xfree(info.xmms2.date);
|
||||
xfree(info.xmms2.status);
|
||||
xfree(info.xmms2.playlist);
|
||||
free_and_zero(info.xmms2.artist);
|
||||
free_and_zero(info.xmms2.album);
|
||||
free_and_zero(info.xmms2.title);
|
||||
free_and_zero(info.xmms2.genre);
|
||||
free_and_zero(info.xmms2.comment);
|
||||
free_and_zero(info.xmms2.url);
|
||||
free_and_zero(info.xmms2.date);
|
||||
free_and_zero(info.xmms2.status);
|
||||
free_and_zero(info.xmms2.playlist);
|
||||
}
|
||||
|
||||
void connection_lost(void *p)
|
||||
|
Loading…
x
Reference in New Issue
Block a user