commit d6c1d94ced56648b1877f0e9a574a4ea9b396694
parent 1e4216f456a14f42c1fa67f73fe8bcddac9a93c6
Author: Paco Esteban <paco@e1e0.net>
Date: Fri, 12 Feb 2021 15:53:51 +0100
fix leaks on index and rss listings
Diffstat:
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/ssnail.c b/ssnail.c
@@ -567,6 +567,8 @@ error:
static void
add_index_entry(char **index_listing, struct article *a)
{
+ char *tmp = NULL;
+
if (!index_listing || !a)
return;
@@ -574,9 +576,13 @@ add_index_entry(char **index_listing, struct article *a)
"%s<li><a href=\"%s\" title=\"%s\">%s</a></li>\n";
char *href = strrchr(a->dst_path, '/');
- if (href)
+ if (href) {
+ /* keep the old listing address so we don't leak */
+ tmp = *index_listing;
asprintf(index_listing, entry_format, *index_listing,
href, a->date, a->title);
+ free(tmp);
+ }
}
struct article *
@@ -610,7 +616,7 @@ add_rss_entry(char **rss_listing, struct article *a, char *url)
struct tm timeinfo;
char *content = NULL, *html_file = NULL,
- *link = NULL, pub_date[LONG_DATE_Z];
+ *link = NULL, pub_date[LONG_DATE_Z], *tmp = NULL;
const char *entry_format =
"%s<item>\n"
"<guid>%s</guid>\n"
@@ -636,9 +642,13 @@ add_rss_entry(char **rss_listing, struct article *a, char *url)
if (html_file)
link = build_full_path(url, html_file);
- if (link && content)
+ if (link && content) {
+ /* keep the old listing address so we don't leak */
+ tmp = *rss_listing;
asprintf(rss_listing, entry_format, *rss_listing,
link, link, a->author, a->title, pub_date, content);
+ free(tmp);
+ }
out:
free(link);