ssnail

crappy and opinionated static site generator
git clone https://git.e1e0.net/ssnail.git
Log | Files | Refs | README | LICENSE

commit 1021b15eb2116a531a03a0b7d5c0e61afdac0e55
parent 1db68eb6d9108721555ac7195dd5b92ce1f494b5
Author: Paco Esteban <paco@e1e0.net>
Date:   Sun, 24 May 2020 17:32:54 +0200

better handle free of linked list allocated memory

I hope ...

Diffstat:
Mssnail.c | 28++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/ssnail.c b/ssnail.c @@ -45,6 +45,9 @@ struct article { SLIST_ENTRY(article) entries; }; +struct article *a = NULL; +SLIST_HEAD(listhead, article) head; + char *str_rep(const char *, const char *, const char *); int gen_html(char **, size_t *, char **, char **, char **, char *, size_t); int build_full_path(char *, char *, char *); @@ -52,6 +55,7 @@ int load_from_file(char **, char *); void usage(); int populate_article_entry(struct article *); int write_html(struct article *); +void articleq_free(struct listhead *); int main(int argc, char *argv[]) @@ -60,7 +64,7 @@ main(int argc, char *argv[]) struct dirent *dp; int ch; char srcdir[PATH_MAX] = "", dstdir[PATH_MAX] = "", *fbuf = NULL; - struct article *a = NULL, *ap = NULL; + struct article *ap = NULL; while ((ch = getopt(argc, argv, "s:d:")) != -1) { switch (ch) { @@ -77,9 +81,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - SLIST_HEAD(listhead, article) head; SLIST_INIT(&head); // init the linked list - // src and dst dir are mandatory. if (srcdir[0] == '\0' || dstdir[0] == '\0') usage(); @@ -111,14 +113,28 @@ main(int argc, char *argv[]) } closedir(dirp); - /* TODO: free the linked list structure <06-05-2020, paco> */ - free(ap); - free(a); + articleq_free(&head); free(fbuf); return 0; } +void +articleq_free(struct listhead *h) +{ + struct article *a; + + SLIST_FOREACH(a, h, entries) { + SLIST_REMOVE(h, a, article, entries); + free(a->orig_content); + free(a->html_content); + free(a->title); + free(a->author); + free(a->date); + free(a); + } +} + char * str_rep(const char *s, const char *oldW, const char *newW) {