gerror: Don't leak memory when overwrite warning
authorDan Winship <danw@gnome.org>
Thu, 7 Nov 2013 21:38:52 +0000 (22:38 +0100)
committerStef Walter <stefw@gnome.org>
Sun, 10 Nov 2013 21:40:08 +0000 (22:40 +0100)
Even though we can't always make no-leak guarantees when g_warning()
in this case we're testing this behavior in tests, and it would be
good to be able to valgrind this.

https://bugzilla.gnome.org/show_bug.cgi?id=711751

glib/gerror.c
glib/tests/error.c

index 809d0c940af1cf86723fd2c655d8253503a5c0db..81e6b716cfccf0463464667505db284be893286f 100644 (file)
@@ -563,7 +563,10 @@ g_set_error (GError      **err,
   if (*err == NULL)
     *err = new;
   else
-    g_warning (ERROR_OVERWRITTEN_WARNING, new->message); 
+    {
+      g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
+      g_error_free (new);
+    }
 }
 
 /**
@@ -619,7 +622,10 @@ g_propagate_error (GError **dest,
   else
     {
       if (*dest != NULL)
-        g_warning (ERROR_OVERWRITTEN_WARNING, src->message);
+        {
+          g_warning (ERROR_OVERWRITTEN_WARNING, src->message);
+          g_error_free (src);
+        }
       else
         *dest = src;
     }
index 81b4055dd098bdee9f23361013edf6059222957e..ebbd965dc075b575341c60dcec4a159f212c467c 100644 (file)
@@ -28,10 +28,7 @@ test_overwrite (void)
   g_test_assert_expected_messages ();
 
   g_assert_error (dest, G_MARKUP_ERROR, G_MARKUP_ERROR_EMPTY);
-  g_assert_error (src, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE);
   g_error_free (dest);
-  g_error_free (src);
-
 }
 
 static void