After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 567181 - Leak in constructors throwing errors
Leak in constructors throwing errors
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator: GError
0.5.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on: 564944
Blocks:
 
 
Reported: 2009-01-09 17:31 UTC by Jürg Billeter
Modified: 2010-01-27 20:48 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jürg Billeter 2009-01-09 17:31:07 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).
Comment 1 Jürg Billeter 2009-01-09 17:32:44 UTC
The return statement has been fixed in the meantime, however, the object is still leaked in the error case.
Comment 2 Hans Vercammen 2009-01-30 06:39:28 UTC
(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.

Comment 3 Michael 'Mickey' Lauer 2009-10-08 12:27:02 UTC
Meanwhile the return statement is fixed again. The leaking remains open though.
Comment 4 Thijs Vermeir 2009-10-30 23:31:02 UTC
This patch fixes the memleak in the constructor:

http://github.com/lovebug356/vala/commit/19a790fe0d211578afb267ebf153fa0493d7ed64
Comment 5 Jürg Billeter 2010-01-27 20:48:14 UTC
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.