Crashing in RSS code probably fixed. Memory leak in prss fixed.
authorToni Spets <spets@users.sourceforge.net>
Sun, 3 Jun 2007 08:58:05 +0000 (08:58 +0000)
committerToni Spets <spets@users.sourceforge.net>
Sun, 3 Jun 2007 08:58:05 +0000 (08:58 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@874 7f574dfc-610e-0410-a909-a81674777703

src/prss.c
src/prss.h
src/rss.c

index cab706b..66c8114 100644 (file)
@@ -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;
index 89fa771..cb43b53 100644 (file)
@@ -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
index d15b258..41e6ec6 100644 (file)
--- 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;
 }