talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 9f8c2f7553ef5010e31d603b550fe09cd207b0ec
parent 3b1b0406282b260339f3bb070d515d829036b5f4
Author: wwp <subscript@free.fr>
Date:   Tue, 28 Sep 2021 15:49:39 +0200

Fix CID 1491122, 1491118, 1491138, 1491092, 1491098 and 1491340: resource leaks.
Fix an extra leaks in opml parsing.
Fix CID 1491366: unchecked return value.

Diffstat:
Msrc/plugins/rssyl/libfeed/feed.c | 6++++--
Msrc/plugins/rssyl/libfeed/parser_opml.c | 35+++++++++++++++++++----------------
Msrc/plugins/rssyl/parse822.c | 9++++++---
Msrc/plugins/rssyl/rssyl.c | 12+++++++-----
Msrc/plugins/rssyl/rssyl_deleted.c | 6++++--
Msrc/plugins/rssyl/rssyl_update_comments.c | 4+++-
Msrc/plugins/rssyl/rssyl_update_format.c | 2++
7 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/src/plugins/rssyl/libfeed/feed.c b/src/plugins/rssyl/libfeed/feed.c @@ -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) diff --git a/src/plugins/rssyl/libfeed/parser_opml.c b/src/plugins/rssyl/libfeed/parser_opml.c @@ -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); } diff --git a/src/plugins/rssyl/parse822.c b/src/plugins/rssyl/parse822.c @@ -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; diff --git a/src/plugins/rssyl/rssyl.c b/src/plugins/rssyl/rssyl.c @@ -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); diff --git a/src/plugins/rssyl/rssyl_deleted.c b/src/plugins/rssyl/rssyl_deleted.c @@ -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); diff --git a/src/plugins/rssyl/rssyl_update_comments.c b/src/plugins/rssyl/rssyl_update_comments.c @@ -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); diff --git a/src/plugins/rssyl/rssyl_update_format.c b/src/plugins/rssyl/rssyl_update_format.c @@ -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; }