GNOME Bugzilla – Bug 557856
Lose objects unref when exception throws
Last modified: 2009-01-01 19:04:01 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:
qualification: this bug occurs only in "try" scope.
Created attachment 125542 [details] [review] Bugfix for this bug
Created attachment 125543 [details] [review] Uncatched errors too
Created attachment 125544 [details] [review] Former was just wrong, this one checks for current_try too
Created attachment 125545 [details] testcase
Created attachment 125546 [details] testcase.c
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.