tests: unref GVariant objects
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 5 Dec 2022 13:22:38 +0000 (14:22 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 5 Dec 2022 13:47:29 +0000 (14:47 +0100)
We need to drop the reference count of the GVariants we create when
packing hogs and line names. This fixes all memory leaks in tests that
are caused by this bug.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
tests/tests-chip.c
tests/tests-line-info.c

index efb4f74d93f8bcc9b2ad151da256ddf65cfa736a..c512908c77b2aa82dd53ed0f4e84a0a5c611f002 100644 (file)
@@ -80,10 +80,11 @@ GPIOD_TEST_CASE(find_line_bad)
 
        g_autoptr(GPIOSimChip) sim = NULL;
        g_autoptr(struct_gpiod_chip) chip = NULL;
+       g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
 
        sim = g_gpiosim_chip_new(
                        "num-lines", 8,
-                       "line-names", gpiod_test_package_line_names(names),
+                       "line-names", vnames,
                         NULL);
 
        chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
@@ -106,10 +107,11 @@ GPIOD_TEST_CASE(find_line_good)
 
        g_autoptr(GPIOSimChip) sim = NULL;
        g_autoptr(struct_gpiod_chip) chip = NULL;
+       g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
 
        sim = g_gpiosim_chip_new(
                        "num-lines", 8,
-                       "line-names", gpiod_test_package_line_names(names),
+                       "line-names", vnames,
                        NULL);
 
        chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
@@ -131,10 +133,11 @@ GPIOD_TEST_CASE(find_line_duplicate)
 
        g_autoptr(GPIOSimChip) sim = NULL;
        g_autoptr(struct_gpiod_chip) chip = NULL;
+       g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
 
        sim = g_gpiosim_chip_new(
                        "num-lines", 8,
-                       "line-names", gpiod_test_package_line_names(names),
+                       "line-names", vnames,
                        NULL);
 
        chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));
index 8ec1b1bc49ec5d61719aeed8843db3cf12210206..a580b714ae7d629b4e573c8002266b60a1d511d4 100644 (file)
@@ -65,11 +65,13 @@ GPIOD_TEST_CASE(line_info_basic_properties)
        g_autoptr(struct_gpiod_chip) chip = NULL;
        g_autoptr(struct_gpiod_line_info) info4 = NULL;
        g_autoptr(struct_gpiod_line_info) info6 = NULL;
+       g_autoptr(GVariant) vnames = gpiod_test_package_line_names(names);
+       g_autoptr(GVariant) vhogs = gpiod_test_package_hogs(hogs);
 
        sim = g_gpiosim_chip_new(
                        "num-lines", 8,
-                       "line-names", gpiod_test_package_line_names(names),
-                       "hogs", gpiod_test_package_hogs(hogs),
+                       "line-names", vnames,
+                       "hogs", vhogs,
                        NULL);
 
        chip = gpiod_test_open_chip_or_fail(g_gpiosim_chip_get_dev_path(sim));