changeset 343:5e6afbf844ae

post: don't leak tags/comment/post body
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 20 Apr 2013 03:12:54 +0000
parents 97286acd3b95
children 4566cdf1d128
files post.c
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/post.c	Sat Apr 20 03:04:33 2013 +0000
+++ b/post.c	Sat Apr 20 03:12:54 2013 +0000
@@ -365,17 +365,27 @@
 		err = __load_post_body(&post);
 
 err:
-	if (err)
-		destroy_post(&post);
-	else
+	if (!err)
 		__store_vars(req, "posts", &post, titlevar);
 
+	destroy_post(&post);
+
 	return err;
 }
 
 void destroy_post(struct post *post)
 {
+	struct post_tag *pt, *pttmp;
+	struct comment *com, *comtmp;
+
+	list_for_each_entry_safe(pt, pttmp, &post->tags, list)
+		free(pt);
+
+	list_for_each_entry_safe(com, comtmp, &post->comments, list)
+		free(com);
+
 	free(post->title);
+	free(post->body);
 }
 
 #if 0