1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 04:32:55 +00:00

cpp-ify prioqueue.c and use free_and_zero in [p-r]*.cc where appropriate

This commit is contained in:
Nikolas Garofil 2010-02-24 02:46:45 +01:00
parent 6092d063c9
commit 4afe96b9ce
6 changed files with 29 additions and 46 deletions

View File

@ -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

View File

@ -32,6 +32,7 @@
*
*/
#include "conky.h"
#include <limits.h> /* INT_MAX */
#include <stdlib.h>
#include <string.h>
@ -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);
}
}

View File

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

View File

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

View File

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

View File

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