Fix CID 1491122, 1491118, 1491138, 1491092, 1491098 and 1491340: resource leaks.
authorwwp <subscript@free.fr>
Tue, 28 Sep 2021 13:49:39 +0000 (15:49 +0200)
committerwwp <subscript@free.fr>
Tue, 28 Sep 2021 13:49:39 +0000 (15:49 +0200)
Fix an extra leaks in opml parsing.
Fix CID 1491366: unchecked return value.

src/plugins/rssyl/libfeed/feed.c
src/plugins/rssyl/libfeed/parser_opml.c
src/plugins/rssyl/parse822.c
src/plugins/rssyl/rssyl.c
src/plugins/rssyl/rssyl_deleted.c
src/plugins/rssyl/rssyl_update_comments.c
src/plugins/rssyl/rssyl_update_format.c

index 56f693ac51ba8fcf63a6bbc8b3a6bdfe772272a7..cac9af825f05562c3b2ca189eb00e930ff9a919a 100644 (file)
@@ -348,8 +348,10 @@ cleanup:
 
        /* Cleanup, we should be done. */
        XML_ParserFree(feed_ctx->parser);
-       g_free(feed_ctx->name);
-       g_free(feed_ctx->mail);
+       if (feed_ctx->name != NULL)
+               g_free(feed_ctx->name);
+       if (feed_ctx->mail != NULL)
+               g_free(feed_ctx->mail);
        if (feed_ctx->str != NULL)
                g_string_free(feed_ctx->str, TRUE);
        if (feed_ctx->xhtml_str != NULL)
index 4e3484141fd4f1b18114fe18c9b9abbdea53874d..575ffc9d363c52a33f6af2621e53770f43dc665c 100644 (file)
@@ -102,30 +102,33 @@ void opml_process(gchar *path, OPMLProcessFunc function, gpointer data)
        XML_SetUnknownEncodingHandler(ctx->parser,
                        feed_parser_unknown_encoding_handler, NULL);
 
-       g_file_get_contents(path, &contents, NULL, &error);
-
-       if( error || !contents )
-               return;
+       if( !g_file_get_contents(path, &contents, NULL, &error) ) {
+               g_warning("error: '%s'", error->message);
+               g_error_free(error);
+       }    
 
+       if( contents ) {
 /*
-       lines = g_strsplit(contents, '\n', 0);
+               lines = g_strsplit(contents, '\n', 0);
 
-       while( lines[i] ) {
-               status = XML_Parse(ctx->parser, lines[i], strlen(lines[i]), FALSE);
-               if( status == XML_STATUS_ERROR ) {
-                       err = XML_GetErrorCode(ctx->parser);
-                       sprintf(stderr, "\nExpat: --- %s\n\n", XML_ErrorString(err));
+               while( lines[i] ) {
+                       status = XML_Parse(ctx->parser, lines[i], strlen(lines[i]), FALSE);
+                       if( status == XML_STATUS_ERROR ) {
+                               err = XML_GetErrorCode(ctx->parser);
+                               sprintf(stderr, "\nExpat: --- %s\n\n", XML_ErrorString(err));
+                       }
                }
-       }
 */
-
-       status = XML_Parse(ctx->parser, contents, strlen(contents), FALSE);
-       err = XML_GetErrorCode(ctx->parser);
-       fprintf(stderr, "\nExpat: --- %s (%s)\n\n", XML_ErrorString(err),
+               status = XML_Parse(ctx->parser, contents, strlen(contents), FALSE);
+               err = XML_GetErrorCode(ctx->parser);
+               fprintf(stderr, "\nExpat: --- %s (%s)\n\n", XML_ErrorString(err),
                        (status == XML_STATUS_OK ? "OK" : "NOT OK"));
 
-       XML_Parse(ctx->parser, "", 0, TRUE);
+               XML_Parse(ctx->parser, "", 0, TRUE);
+       }    
 
        XML_ParserFree(ctx->parser);
+       if (ctx->str != NULL)
+               g_string_free(ctx->str, TRUE);
        g_free(ctx);
 }
index c675e4376143bb12d4175707fe45926ca4229de4..af9f2206cceb24f4f493960001f2773b678e6f3a 100644 (file)
@@ -62,9 +62,7 @@ FeedItem *rssyl_parse_folder_item_file(gchar *path)
 
        debug_print("RSSyl: parsing '%s'\n", path);
 
-       g_file_get_contents(path, &contents, NULL, &error);
-
-       if( error ) {
+       if( !g_file_get_contents(path, &contents, NULL, &error) ) {
                g_warning("error: '%s'", error->message);
                g_error_free(error);
        }
@@ -198,6 +196,11 @@ FeedItem *rssyl_parse_folder_item_file(gchar *path)
                        if( !strcmp(lines[i], RSSYL_TEXT_START) ) {
                                debug_print("RSSyl: Leading html tag found at line %d\n", i);
                                past_html_tag = TRUE;
+                               if (body)
+                               {
+                                       g_warning("unexpected leading html tag found at line %d", i);
+                                   g_string_free(body, TRUE);
+                               }
                                body = g_string_new("");
                                i++;
                                continue;
index 3a9517dcd5727beab8c80669dc3093d12265063f..943e37e995d3557cd5da0c34ea92cf6597b4262e 100644 (file)
@@ -928,7 +928,7 @@ static gboolean rssyl_subscribe_uri(Folder *folder, const gchar *uri)
 static void rssyl_copy_private_data(Folder *folder, FolderItem *oldi,
                FolderItem *newi)
 {
-       gchar *dpathold, *dpathnew;
+       gchar *dpathold, *dpathnew, *pathold, *pathnew;
        RFolderItem *olditem = (RFolderItem *)oldi,
                                                                        *newitem = (RFolderItem *)newi;
 
@@ -984,11 +984,13 @@ static void rssyl_copy_private_data(Folder *folder, FolderItem *oldi,
        newitem->fetching_comments = olditem->fetching_comments;
        newitem->last_update = olditem->last_update;
 
-       dpathold = g_strconcat(rssyl_item_get_path(oldi->folder, oldi),
-                       G_DIR_SEPARATOR_S, RSSYL_DELETED_FILE, NULL);
-       dpathnew = g_strconcat(rssyl_item_get_path(newi->folder, newi),
-                       G_DIR_SEPARATOR_S, RSSYL_DELETED_FILE, NULL);
+       pathold = rssyl_item_get_path(oldi->folder, oldi);
+       dpathold = g_strconcat(pathold, G_DIR_SEPARATOR_S, RSSYL_DELETED_FILE, NULL);
+       pathnew = rssyl_item_get_path(newi->folder, newi);
+       dpathnew = g_strconcat(pathnew, G_DIR_SEPARATOR_S, RSSYL_DELETED_FILE, NULL);
        move_file(dpathold, dpathnew, TRUE);
+       g_free(pathold);
+       g_free(pathnew);
        g_free(dpathold);
        g_free(dpathnew);
 
index 3cc5325fbd7b16e9ead4c49a27d0f119047d71d1..32c0c34a5be2d5afe6b4f6dd2b858bb5f3c8987d 100644 (file)
@@ -120,8 +120,6 @@ void rssyl_deleted_update(RFolderItem *ritem)
                return;
        }
 
-       g_free(deleted_file);
-
        while (lines[i]) {
                line = g_strsplit(lines[i], ": ", 2);
                if (line[0] && line[1] && strlen(line[0]) && strlen(line[1])) {
@@ -140,6 +138,10 @@ void rssyl_deleted_update(RFolderItem *ritem)
                g_strfreev(line);
                i++;
        }
+       if (ditem)
+               g_warning("short read while parsing the list of deleted items for '%s'\n",
+                               deleted_file);
+       g_free(deleted_file);
 
        g_free(lines);
        g_free(contents);
index ae831ed482a2c3dadf2992535f1d45e3cf05aa66..cf6c618a22cedf5a741dc8550f8cbce3759320f5 100644 (file)
@@ -94,8 +94,10 @@ void rssyl_update_comments(RFolderItem *ritem)
 
                if( (num = to_number(d)) > 0) {
                        fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d);
-                       if (!g_file_test(fname, G_FILE_TEST_IS_REGULAR))
+                       if (!g_file_test(fname, G_FILE_TEST_IS_REGULAR)) {
+                               g_free(fname);
                                continue;
+                       }
 
                        debug_print("RSSyl: starting to parse '%s'\n", d);
 
index 44804294481d99c513eaf0d5880e8677cf14eb61..97345877266e91cb120d68b7f40329c612fd9beb 100644 (file)
@@ -255,6 +255,8 @@ static void rssyl_update_format_move_contents(FolderItem *olditem,
        if ((d = g_dir_open(oldpath, 0, &error)) == NULL) {
                debug_print("RSSyl: (FORMAT) couldn't open dir '%s': %s\n", oldpath,
                                error->message);
+               g_free(oldpath);
+               g_free(newpath);
                g_error_free(error);
                return;
        }