From 615fb197231d57d98ef6e5fd164df244449bafa5 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Sun, 3 Jun 2007 08:58:05 +0000 Subject: [PATCH] Crashing in RSS code probably fixed. Memory leak in prss fixed. git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@874 7f574dfc-610e-0410-a909-a81674777703 --- src/prss.c | 6 ++++++ src/prss.h | 4 +++- src/rss.c | 8 +++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/prss.c b/src/prss.c index cab706b0..66c8114f 100644 --- a/src/prss.c +++ b/src/prss.c @@ -26,6 +26,8 @@ #define PARSE_OPTIONS 0 #endif +PRSS* prss_parse_doc(xmlDocPtr doc); + PRSS* prss_parse_data(const char* xml_data) { xmlDocPtr doc = xmlReadMemory(xml_data, strlen(xml_data), "", NULL, PARSE_OPTIONS); @@ -180,6 +182,8 @@ static inline int parse_rss_0_9x(PRSS* res, xmlNodePtr root) PRSS* prss_parse_doc(xmlDocPtr doc) { + // FIXME: doc shouldn't be freed after failure when called explicitly from program! + xmlNodePtr root = xmlDocGetRootElement(doc); PRSS* result = malloc(sizeof(PRSS)); prss_null(result); @@ -190,6 +194,7 @@ PRSS* prss_parse_doc(xmlDocPtr doc) // RSS 1.0 document if (!parse_rss_1_0(result, root)) { free(result); + xmlFreeDoc(doc); return NULL; } return result; @@ -197,6 +202,7 @@ PRSS* prss_parse_doc(xmlDocPtr doc) // RSS 2.0 or <1.0 document if (!parse_rss_2_0(result, root)) { free(result); + xmlFreeDoc(doc); return NULL; } return result; diff --git a/src/prss.h b/src/prss.h index 89fa7718..cb43b53e 100644 --- a/src/prss.h +++ b/src/prss.h @@ -50,7 +50,9 @@ typedef struct PRSS_ { /* Functions for parsing RSS-data */ PRSS* prss_parse_data(const char *xml_data); PRSS* prss_parse_file(const char *xml_file); -PRSS* prss_parse_doc(xmlDocPtr doc); + +// Works wrong currently when called from application! +//PRSS* prss_parse_doc(xmlDocPtr doc); /* Frees the PRSS-stucture returned by prss_parse_*. * The memory area pointed by data becomes invalid diff --git a/src/rss.c b/src/rss.c index d15b2585..41e6ec65 100644 --- a/src/rss.c +++ b/src/rss.c @@ -112,8 +112,10 @@ get_rss_info(char *uri, int delay) if(!rss_delay(last_update, delay)) return curdata; // wait for delay to pass - if(curdata != NULL) + if(curdata != NULL) { prss_free(curdata); // clean up old data + curdata = NULL; + } curl = curl_easy_init(); if(curl) { @@ -130,10 +132,10 @@ get_rss_info(char *uri, int delay) } else ERR("No data from server"); - curfeed->data = curdata; - curl_easy_cleanup(curl); } + curfeed->data = curdata; + return curdata; }