GNOME Bugzilla – Bug 567181
Leak in constructors throwing errors
Last modified: 2010-01-27 20:48:14 UTC
+++ This bug was initially created as a clone of Bug #564944 +++ Constructors which throw errors generate code (in the *_construct function) code that looks something like this: Foo* foo_construct (GType object_type, GError** error) { GError * inner_error; Foo * self; inner_error = NULL; self = g_object_newv (object_type, 0, NULL); inner_error = g_error_new (ERROR, ERROR_FOOBAR, "Foobar!"); if (inner_error != NULL) { g_propagate_error (error, inner_error); return; } return self; } Notice that inside of the if block, there is a return without a value, which can cause problems later on (warnings about assertion `G_IS_OBJECT (object)' failed, segfaults). I think that if there is an error, it should either unref the object and return null, or return self and leave it to the caller to unref (which it does).
The return statement has been fixed in the meantime, however, the object is still leaked in the error case.
(In reply to comment #1) > The return statement has been fixed in the meantime, however, the object is > still leaked in the error case. Regression has occurred somewhere. Last checked with r2409.
Meanwhile the return statement is fixed again. The leaking remains open though.
This patch fixes the memleak in the constructor: http://github.com/lovebug356/vala/commit/19a790fe0d211578afb267ebf153fa0493d7ed64
commit ec257a60267d843b22fb34f3cb5464a641104136 Author: Thijs Vermeir <thijsvermeir@gmail.com> Date: Fri Oct 30 23:46:34 2009 +0100 GError: Fix leak when throwing an error in the constructor Fixes bug 567818.