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 710882 - Implicitly created variants are leaked
Implicitly created variants are leaked
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings: GLib
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2013-10-25 14:56 UTC by Lars Karlitski
Modified: 2017-03-25 14:49 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Lars Karlitski 2013-10-25 14:56:32 UTC
When passing a value into a function expecting an GVariant like this

    var action = new SimpleAction.stateful ("test", null, 5),

vala leaks the implicitly created variant:

    static GVariant* _variant_new1 (gint value) {
        return g_variant_ref_sink (g_variant_new_int32 (value));
    }

    /* ... */

    _tmp0_ = _variant_new1 (5);
    _tmp1_ = g_simple_action_new_stateful ("test", NULL, _tmp0_);
    /* _tmp0_ is never freed */
Comment 1 Luca Bruno 2013-10-25 15:04:50 UTC
Does g_simple_action_new_stateful takes ownership of the gvariant? The docs aren't very clear.
Comment 2 Lars Karlitski 2013-10-25 15:18:32 UTC
No, g_simple_action_new_stateful() simply takes another ref.

To be more precise, it sinks the variant that you pass in with g_variant_ref_sink(). This is so that you can pass a floating variant without having to unref it later. Vala passes an already-sinked variant though.
Comment 3 Luca Bruno 2013-10-26 09:38:12 UTC
commit c726aefc51e2bb0d23f37066d365cb3d8456f195
Author: Luca Bruno <lucabru@src.gnome.org>
Date:   Sat Oct 26 11:32:23 2013 +0200

    Fix memory leak when assigning an owned gvariant to an unowned variable
    
    Fixes bug 710882.

This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
Comment 4 Luca Bruno 2013-10-26 09:38:47 UTC
Wrong hash: b6f7cd6c2aaf5dee64f618a0e06b0d0c157ea352