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;