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 786388 - Memory leak in code generated for printf-like functions with gettext and an argument that can fail
Memory leak in code generated for printf-like functions with gettext and an a...
Status: VERIFIED DUPLICATE of bug 736774
Product: vala
Classification: Core
Component: Code Generator
0.37.x
Other Linux
: Normal minor
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2017-08-16 20:01 UTC by Gugurumbe
Modified: 2017-08-25 13:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test.c with the bogus code at the end of the file (1.07 KB, text/x-csrc)
2017-08-16 20:01 UTC, Gugurumbe
Details

Description Gugurumbe 2017-08-16 20:01:10 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 */
}
Comment 1 Rico Tzschichholz 2017-08-21 15:39:59 UTC

*** This bug has been marked as a duplicate of bug 736774 ***
Comment 2 Gugurumbe 2017-08-25 13:06:28 UTC
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_);
}