diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 971a83ba..f3205f67 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,7 +37,7 @@ endif(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build.h) set(conky_sources colours.cc combine.cc common.cc conky.cc core.cc diskio.cc entropy.cc exec.cc fs.cc mail.cc mixer.cc net_stat.cc template.cc mboxscan.cc read_tcp.cc scroll.cc specials.cc tailhead.cc - temphelper.cc text_object.cc timeinfo.cc top.cc algebra.cc prioqueue.c proc.cc + temphelper.cc text_object.cc timeinfo.cc top.cc algebra.cc prioqueue.cc proc.cc user.cc) # add timed thread library diff --git a/src/prioqueue.c b/src/prioqueue.cc similarity index 96% rename from src/prioqueue.c rename to src/prioqueue.cc index 0c9d9927..b546a6d5 100644 --- a/src/prioqueue.c +++ b/src/prioqueue.cc @@ -32,6 +32,7 @@ * */ +#include "conky.h" #include /* INT_MAX */ #include #include @@ -69,7 +70,7 @@ struct prio_queue *init_prio_queue(void) { struct prio_queue *retval; - retval = malloc(sizeof(struct prio_queue)); + retval = (struct prio_queue *) malloc(sizeof(struct prio_queue)); memset(retval, 0, sizeof(struct prio_queue)); /* use pq_free_nop by default */ @@ -110,7 +111,7 @@ static struct prio_elem *init_prio_elem(void *data) { struct prio_elem *retval; - retval = malloc(sizeof(struct prio_elem)); + retval = (struct prio_elem *) malloc(sizeof(struct prio_elem)); memset(retval, 0, sizeof(struct prio_elem)); retval->data = data; @@ -171,8 +172,7 @@ check_cur_size: queue->cur_size--; queue->tail = queue->tail->prev; (*queue->free)(queue->tail->next->data); - free(queue->tail->next); - queue->tail->next = NULL; + free_and_zero(queue->tail->next); } } diff --git a/src/prioqueue.h b/src/prioqueue.h index 7252a5f9..764be23b 100644 --- a/src/prioqueue.h +++ b/src/prioqueue.h @@ -25,9 +25,6 @@ #ifndef _PRIOQUEUE_H #define _PRIOQUEUE_H -#ifdef __cplusplus -extern "C" { -#endif /* forward-define for private data */ struct prio_queue; @@ -66,8 +63,4 @@ void *pop_prio_elem(prio_queue_t); /* clear and free the given queue */ void free_prio_queue(prio_queue_t); -#ifdef __cplusplus -} -#endif - #endif /* _PRIOQUEUE_H */ diff --git a/src/prss.cc b/src/prss.cc index 72a7e86c..2cbedcbe 100644 --- a/src/prss.cc +++ b/src/prss.cc @@ -49,19 +49,20 @@ void free_rss_items(PRSS *data) { int i; - for (i = 0; i < data->item_count; i++) { -#define CLEAR(a) if (data->items[i].a) { free(data->items[i].a); data->items[i].a = 0; } - CLEAR(title); - CLEAR(link); - CLEAR(description); - CLEAR(category); - CLEAR(pubDate); - CLEAR(guid); + if(data->items) { + for (i = 0; i < data->item_count; i++) { +#define CLEAR(a) free_and_zero(data->items[i].a); + CLEAR(title); + CLEAR(link); + CLEAR(description); + CLEAR(category); + CLEAR(pubDate); + CLEAR(guid); #undef CLEAR + } + free_and_zero(data->items); + data->item_count = 0; } - free(data->items); - data->item_count = 0; - data->items = 0; } void prss_free(PRSS *data) @@ -69,16 +70,10 @@ void prss_free(PRSS *data) if (!data) { return; } - if (data->version) { - free(data->version); - data->version = 0; - } - if (data->items) { - free_rss_items(data); - } + free_and_zero(data->version); + free_rss_items(data); data->version = 0; - data->items = 0; -#define CLEAR(a) if (data->a) { free(data->a); data->a = 0; } +#define CLEAR(a) free_and_zero(data->a); CLEAR(title); CLEAR(link); CLEAR(description); @@ -116,7 +111,7 @@ static inline void read_item(PRSS_Item *res, xmlNodePtr data) } #define ASSIGN(a) if (strcasecmp((const char*)data->name, #a) == EQUAL) { \ - if (res->a) free(res->a); \ + free_and_zero(res->a); \ res->a = strdup((const char*)child->content); \ continue; \ } @@ -143,7 +138,7 @@ static inline void read_element(PRSS *res, xmlNodePtr n) } #define ASSIGN(a) if (strcasecmp((const char*)n->name, #a) == EQUAL) { \ - if (res->a) free(res->a); \ + free_and_zero(res->a); \ res->a = strdup((const char*)child->content); \ return; \ } @@ -188,9 +183,9 @@ static inline int parse_rss_2_0(PRSS *res, xmlNodePtr root) } } - if (res->version) free(res->version); + free_and_zero(res->version); res->version = strndup("2.0", text_buffer_size); - if (res->items) free_rss_items(res); + free_rss_items(res); res->items = (PRSS_Item*) malloc(items * sizeof(PRSS_Item)); res->item_count = 0; @@ -221,9 +216,9 @@ static inline int parse_rss_1_0(PRSS *res, xmlNodePtr root) } } - if (res->version) free(res->version); + free_and_zero(res->version); res->version = strndup("1.0", text_buffer_size); - if (res->items) free_rss_items(res); + free_rss_items(res); res->items = (PRSS_Item*) malloc(items * sizeof(PRSS_Item)); res->item_count = 0; diff --git a/src/read_tcp.cc b/src/read_tcp.cc index 1b73489c..0577769d 100644 --- a/src/read_tcp.cc +++ b/src/read_tcp.cc @@ -109,8 +109,6 @@ void free_read_tcp(struct text_object *obj) if (!rtd) return; - if (rtd->host) - free(rtd->host); - free(obj->data.opaque); - obj->data.opaque = NULL; + free_and_zero(rtd->host); + free_and_zero(obj->data.opaque); } diff --git a/src/rss.cc b/src/rss.cc index c1f96ad2..61627ffd 100644 --- a/src/rss.cc +++ b/src/rss.cc @@ -183,8 +183,5 @@ void rss_print_info(struct text_object *obj, char *p, int p_max_size) void rss_free_obj_info(struct text_object *obj) { - if (obj->data.opaque) { - free(obj->data.opaque); - obj->data.opaque = NULL; - } + free_and_zero(obj->data.opaque); }