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 557856 - Lose objects unref when exception throws
Lose objects unref when exception throws
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Errors
0.5.x
Other All
: Normal critical
: ---
Assigned To: Jürg Billeter
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-10-25 12:12 UTC by Alexander Krikunov
Modified: 2009-01-01 19:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Bugfix for this bug (1.06 KB, patch)
2008-12-30 19:07 UTC, Philip Van Hoof
none Details | Review
Uncatched errors too (1.39 KB, patch)
2008-12-30 19:12 UTC, Philip Van Hoof
none Details | Review
Former was just wrong, this one checks for current_try too (2.64 KB, patch)
2008-12-30 19:28 UTC, Philip Van Hoof
committed Details | Review
testcase (1.20 KB, text/plain)
2008-12-30 19:29 UTC, Philip Van Hoof
  Details
testcase.c (14.56 KB, text/plain)
2008-12-30 19:29 UTC, Philip Van Hoof
  Details

Description Alexander Krikunov 2008-10-25 12:12:07 UTC
Please describe the problem:
This vala code:

class MyClass : GLib.Object
{
  ~MyClass()
  {
    stdout.printf("destroying MyObject\n");
  }
}

int main()
{
  try
  {
    stdout.printf("hello, world\n");
    var s = new MyClass();
    throw new GLib.OptionError.FAILED("test exception");
  }
  catch(GLib.OptionError e)
  {
    stderr.printf("error: %s\n", e.message);
  }

  return 0;
}

translated as:

...
		s = myclass_new ();
		inner_error = g_error_new (G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "test exception");
		if (inner_error != NULL) {

...

		}
		(s == NULL ? NULL : (s = (g_object_unref (s), NULL)));
	}
	goto __finally0;
	__catch0_g_option_error:
	{

...

	}
	__finally0:
	;
	return 0;
}

and MyClass instance leak. The correct code is:

...
		s = myclass_new ();
		inner_error = g_error_new (G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "test exception");
		if (inner_error != NULL) {

...

		}
	}
	goto __finally0;
	__catch0_g_option_error:
	{

...

	}
	__finally0:
	;

        // !!!!!!!
        (s == NULL ? NULL : (s = (g_object_unref (s), NULL)));

	return 0;
}


Steps to reproduce:


Actual results:


Expected results:


Does this happen every time?
yes

Other information:
Comment 1 Alexander Krikunov 2008-10-25 14:17:54 UTC
qualification: this bug occurs only in "try" scope.
Comment 2 Philip Van Hoof 2008-12-30 19:07:05 UTC
Created attachment 125542 [details] [review]
Bugfix for this bug
Comment 3 Philip Van Hoof 2008-12-30 19:12:15 UTC
Created attachment 125543 [details] [review]
Uncatched errors too
Comment 4 Philip Van Hoof 2008-12-30 19:28:59 UTC
Created attachment 125544 [details] [review]
Former was just wrong, this one checks for current_try too
Comment 5 Philip Van Hoof 2008-12-30 19:29:20 UTC
Created attachment 125545 [details]
testcase
Comment 6 Philip Van Hoof 2008-12-30 19:29:38 UTC
Created attachment 125546 [details]
testcase.c
Comment 7 Jürg Billeter 2009-01-01 19:04:01 UTC
2009-01-01  Jürg Billeter  <j@bitron.ch>

	* gobject/valaccodebasemodule.vala:
	* gobject/valagerrormodule.vala:

	Fix memory leaks when handling errors, patch by Philip Van Hoof,
	fixes bug 557856

Fixed in r2251.