From 2c8426dcc78fb0deae4aab7a53a364ebf7064a50 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Sun, 3 Jun 2007 11:20:47 +0000 Subject: [PATCH] Again fixed things in the RSS code. Removed possible trailing \n from RSS data. Hopefully fixed iconv memory freeing problems. Graps had non-freed malloced data. git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@876 7f574dfc-610e-0410-a909-a81674777703 --- src/conky.c | 42 +++++++++++++++++++++++++++++++++--------- src/conky.h | 2 ++ src/rss.c | 35 +++++++++++++++++++++++++---------- 3 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/conky.c b/src/conky.c index 8e8719d0..0eb9902d 100644 --- a/src/conky.c +++ b/src/conky.c @@ -333,7 +333,7 @@ unsigned int text_buffer_size = TEXT_BUFFER_SIZE; #ifdef HAVE_ICONV #define CODEPAGE_LENGTH 20 long iconv_selected; -long iconv_count; +long iconv_count = 0; char iconv_converting; static iconv_t **iconv_cd = 0; @@ -360,8 +360,9 @@ void free_iconv(void) { if (iconv_cd) { long i; - for (i = iconv_count; i < 0; i++) { + for (i = 0; i < iconv_count; i++) { if (iconv_cd[i]) { + iconv_close(*iconv_cd[i]); free(iconv_cd[i]); } } @@ -2049,6 +2050,7 @@ static void free_text_objects(unsigned int count, struct text_object *objs) case OBJ_rss: free(objs[i].data.rss.uri); free(objs[i].data.rss.action); + break; #endif case OBJ_pre_exec: case OBJ_battery: @@ -3123,14 +3125,16 @@ static struct text_object *construct_text_object(const char *s, const char *arg, OBJ(rss, 0) if (arg) { int argc, delay, act_par; - char *uri = (char *)malloc(128 * sizeof(char *)); - char *action = (char *)malloc(64 * sizeof(char *)); + char *uri = (char *)malloc(128 * sizeof(char)); + char *action = (char *)malloc(64 * sizeof(char)); argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action, &act_par); obj->data.rss.uri = uri; obj->data.rss.delay = delay; obj->data.rss.action = action; obj->data.rss.act_par = act_par; + + init_rss_info(); } else CRIT_ERR("rss needs arguments: [act_par]"); @@ -4293,18 +4297,28 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object * #ifdef RSS OBJ(rss) { PRSS* data = get_rss_info(obj->data.rss.uri, obj->data.rss.delay); + char *str; if(data == NULL) snprintf(p, p_max_size, "prss: Error reading RSS data\n"); else { if(!strcmp(obj->data.rss.action, "feed_title")) { - snprintf(p, p_max_size, "%s", data->title); + str = data->title; + if(str[strlen(str)-1] == '\n') + str[strlen(str)-1] = 0; // remove trailing new line if one exists + snprintf(p, p_max_size, "%s", str); } else if(!strcmp(obj->data.rss.action, "item_title")) { if(obj->data.rss.act_par < data->item_count) { - snprintf(p, p_max_size, "%s", data->items[obj->data.rss.act_par].title); + str = data->items[obj->data.rss.act_par].title; + if(str[strlen(str)-1] == '\n') + str[strlen(str)-1] = 0; // remove trailing new line if one exists + snprintf(p, p_max_size, "%s", str); } } else if(!strcmp(obj->data.rss.action, "item_desc")) { if(obj->data.rss.act_par < data->item_count) { - snprintf(p, p_max_size, "%s", data->items[obj->data.rss.act_par].description); + str = data->items[obj->data.rss.act_par].description; + if(str[strlen(str)-1] == '\n') + str[strlen(str)-1] = 0; // remove trailing new line if one exists + snprintf(p, p_max_size, "%s", str); } } else if(!strcmp(obj->data.rss.action, "item_titles")) { if(data->item_count > 0) { @@ -4318,6 +4332,9 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object * PRSS_Item *item = &data->items[itmp]; if(i>0) strncat(p, "\n", p_max_size); + str = item->title; + if(str[strlen(str)-1] == '\n') + str[strlen(str)-1] = 0; // remove trailing new line if one exists strncat(p, item->title, p_max_size); } } @@ -6507,10 +6524,17 @@ void clean_up(void) destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection ); info.p_tcp_port_monitor_collection = NULL; #endif +#ifdef RSS + free_rss_info(); +#endif if (specials) { - free (specials); - specials=NULL; + unsigned int i; + for(i=0;i 0) { - for(i = 0; i < num_feeds; i++) { - if(feeds[i].uri != NULL) - if(!strcmp(feeds[i].uri, uri)) { - curfeed = &feeds[i]; - break; - } - } + for(i = 0; i < num_feeds; i++) { + if(feeds[i].uri != NULL) + if(!strcmp(feeds[i].uri, uri)) { + curfeed = &feeds[i]; + break; + } } if(!curfeed) { // new feed if(num_feeds == MAX_FEEDS-1) return NULL; curfeed = &feeds[num_feeds]; - curfeed->uri = (char *)malloc(sizeof(char) * strlen(uri)+1); - strncpy(curfeed->uri, uri, strlen(uri)+1); + curfeed->uri = strdup(uri); num_feeds++; }