tests: fix a GVariant referencing bug
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 31 Jan 2023 14:53:27 +0000 (15:53 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 31 Jan 2023 14:53:27 +0000 (15:53 +0100)
g_variant_new() returns a floating reference that must be converted to
a full reference before returning or else we may get weird reference
counting errors.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
tests/gpiod-test-helpers.c

index 24a6ee494c0f4255a865a58466a6e1e3b134396c..4801b151837fe4360bee35485572ec68992db36a 100644 (file)
@@ -24,7 +24,7 @@ gpiod_test_package_line_names(const struct gpiod_test_line_name *names)
                g_variant_builder_add(builder, "(us)",
                                      name->offset, name->name);
 
-       ret = g_variant_new("a(us)", builder);
+       ret = g_variant_ref_sink(g_variant_new("a(us)", builder));
        g_variant_builder_unref(builder);
 
        return ret;
@@ -42,7 +42,7 @@ GVariant *gpiod_test_package_hogs(const struct gpiod_test_hog *hogs)
                g_variant_builder_add(builder, "(usi)",
                                      hog->offset, hog->name, hog->direction);
 
-       ret = g_variant_new("a(usi)", builder);
+       ret = g_variant_ref_sink(g_variant_new("a(usi)", builder));
        g_variant_builder_unref(builder);
 
        return ret;