f9e5e36755af8ec1f68e33e91404da9136aae861
diff --git a/libsoup/soup-cookie-jar-text.c b/libsoup/soup-cookie-jar-text.c
index 9b6fb66..bf445ae 100644
--- a/libsoup/soup-cookie-jar-text.c
+++ b/libsoup/soup-cookie-jar-text.c
@@ -285,8 +285,10 @@ delete_cookie (const char *filename, SoupCookie *cookie)
 		return;
 
 	f = fopen (filename, "w");
-	if (!f)
+	if (!f) {
+		g_free (contents);
 		return;
+	}
 
 	line = contents;
 	for (p = contents; *p; p++) {
@@ -305,6 +307,7 @@ delete_cookie (const char *filename, SoupCookie *cookie)
 		write_cookie (f, c);
 	soup_cookie_free (c);
 
+	g_free (contents);
 	fclose (f);
 }
 
