From 6b5acff56617bcf8b5c7b525640fd64522176400 Mon Sep 17 00:00:00 2001 From: Darshit Shah <darnir@gmail.com> Date: Sat, 29 Aug 2015 22:52:49 +0530 Subject: [PATCH] Fix memory leaks in unit-test * hsts.c (get_hsts_store_filename): Free the homedir value (close_hsts_test_store): Actually free the store struct too (test_hsts_new_entry): Pass store to close_hsts_test_store() (test_hsts_url_rewrite_superdomain): Same (test_hsts_url_rewrite_congruent): Same (test_hsts_read_database): Same and homedir and store filename * http.c (test_parse_content_disposition): Free the returned filename * url.c (test_append_uri_pathel): Free allocated string --- src/hsts.c | 13 +++++++++---- src/http.c | 1 + src/url.c | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/hsts.c b/src/hsts.c index 6b2d129a..5c4ca357 100644 --- a/src/hsts.c +++ b/src/hsts.c @@ -558,6 +558,7 @@ get_hsts_store_filename (void) fclose (fp); } + xfree (home); return filename; } @@ -575,13 +576,14 @@ open_hsts_test_store (void) } static void -close_hsts_test_store (void) +close_hsts_test_store (hsts_store_t store) { char *filename = NULL; filename = get_hsts_store_filename (); unlink (filename); xfree (filename); + xfree (store); } static const char* @@ -658,7 +660,7 @@ test_hsts_new_entry (void) mu_assert("Should've been no match", match == NO_MATCH); hsts_store_close (s); - close_hsts_test_store (); + close_hsts_test_store (s); return NULL; } @@ -679,7 +681,7 @@ test_hsts_url_rewrite_superdomain (void) TEST_URL_RW (s, "bar.www.foo.com", 80); hsts_store_close (s); - close_hsts_test_store (); + close_hsts_test_store (s); return NULL; } @@ -700,7 +702,7 @@ test_hsts_url_rewrite_congruent (void) TEST_URL_NORW (s, "www.foo.com", 80); hsts_store_close (s); - close_hsts_test_store (); + close_hsts_test_store (s); return NULL; } @@ -736,8 +738,11 @@ test_hsts_read_database (void) TEST_URL_RW (table, "test.example.com", 8080); hsts_store_close (table); + close_hsts_test_store (table); unlink (file); } + xfree (file); + xfree (home); } return NULL; diff --git a/src/http.c b/src/http.c index a65b4bf6..e96cad79 100644 --- a/src/http.c +++ b/src/http.c @@ -4926,6 +4926,7 @@ filename*1=\"B\"", "AA.ext", true }, res == test_array[i].result && (res == false || 0 == strcmp (test_array[i].filename, filename))); + xfree (filename); } return NULL; diff --git a/src/url.c b/src/url.c index 73c8dd0a..d8d6d95b 100644 --- a/src/url.c +++ b/src/url.c @@ -2350,6 +2350,7 @@ test_append_uri_pathel(void) mu_assert ("test_append_uri_pathel: wrong result", strcmp (dest.base, test_array[i].expected_result) == 0); + xfree (dest.base); } return NULL;