GNOME Bugzilla – Bug 786388
Memory leak in code generated for printf-like functions with gettext and an argument that can fail
Last modified: 2017-08-25 13:06:28 UTC
Created attachment 357760 [details] test.c with the bogus code at the end of the file Hello, I came across this bug: test.vala: string s () throws GLib.Error { return "hello"; } void do_fail (string loc, ...) {} void failing () { do_fail (_ (""), s ()); } valac -C test.vala gives: ... _tmp2_ = _ (""); _tmp3_ = _tmp0_; _tmp0_ = NULL; do_fail (_tmp2_, _tmp3_, NULL); _g_free0 (_tmp0_); ... The bug only occurs: - when using a localized string in do_fail; - when s () may throw GLib.Error; - when the localized string is the first parameter. Handling the error does *not* help. Occurs for the debian stable compiler (0.34) and the git version (0.37) Easy workaround: use a local variable void working () { string saved = s (); do_fail (_ (""), saved); /* works */ }
*** This bug has been marked as a duplicate of bug 736774 ***
Thank you! Now it works: _g_free0 frees the non-null _tmp0_ /* test.c generated by valac 0.37.90.6-1d86, the Vala compiler * generated from test.vala, do not modify */ #include <glib.h> #include <glib-object.h> #include <stdlib.h> #include <string.h> #include <glib/gi18n-lib.h> #define _g_free0(var) (var = (g_free (var), NULL)) gchar* s (GError** error); void do_fail (const gchar* loc, ...); void failing (void); gchar* s (GError** error) { gchar* result = NULL; gchar* _tmp0_; _tmp0_ = g_strdup ("hello"); result = _tmp0_; return result; } void do_fail (const gchar* loc, ...) { g_return_if_fail (loc != NULL); } void failing (void) { gchar* _tmp0_ = NULL; gchar* _tmp1_; GError * _inner_error_ = NULL; _tmp1_ = s (&_inner_error_); _tmp0_ = _tmp1_; if (G_UNLIKELY (_inner_error_ != NULL)) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } do_fail (_ (""), _tmp0_, NULL); _g_free0 (_tmp0_); }