Values returned from functions returning Value? are never freed
@jensgeorg
Submitted by Jens Georg Link to original bug (#771737)
Description
==27184== 24 bytes in 1 blocks are definitely lost in loss record 97 of 233
==27184== at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27184== by 0x50DC780: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.1)
==27184== by 0x40088B: foo (in /home/jens/free)
==27184== by 0x4008F1: _vala_main (in /home/jens/free)
==27184== by 0x400930: main (in /home/jens/free)
==27184==
Vala code:
Value? foo() {
Value? v = false;
return v;
}
int main(string[] args)
{
bool b = (bool) foo();
return 0;
}
C code (extract):
GValue* foo (void) {
GValue* result = NULL;
GValue* v = NULL;
GValue* _tmp0_ = NULL;
_tmp0_ = g_new0 (GValue, 1);
g_value_init (_tmp0_, G_TYPE_BOOLEAN);
g_value_set_boolean (_tmp0_, FALSE);
v = _tmp0_;
result = v;
return result;
}
gint _vala_main (gchar** args, int args_length1) {
gint result = 0;
gboolean b = FALSE;
GValue* _tmp0_ = NULL;
_tmp0_ = foo ();
b = g_value_get_boolean (_tmp0_);
result = 0;
return result;
}
I suspect the ? means boxed here instead of nullable, but it still should be freed, no?
If I omit the ? in the declaration of Value? v = false
, I get
==27374== 24 bytes in 1 blocks are definitely lost in loss record 99 of 237
==27374== at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27374== by 0x54A5780: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4800.1)
==27374== by 0x4E46D62: value_copy (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
==27374== by 0x4E47F8A: g_boxed_copy (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.1)
==27374== by 0x400918: _g_value_dup (in /home/jens/free)
==27374== by 0x400939: __g_value_dup0 (in /home/jens/free)
==27374== by 0x400A17: foo (in /home/jens/free)
==27374== by 0x400A8B: _vala_main (in /home/jens/free)
==27374== by 0x400ACA: main (in /home/jens/free)
Edited by Corentin Noël