Commit c4e35871 authored by Christian Kellner's avatar Christian Kellner
Browse files

test: fix various small memory leaks

Add missing g_clear_pointer / g_clear_object calls when a pointer
was re-used during the tests. In MockSysfs, free the force-power
path. In test-glue, use g_autoptr for all allocated GParamSpecs.
parent 78fe16e3
......@@ -102,10 +102,9 @@ union ctrlmsg
NotifySocket *
notify_socket_new (void)
{
NotifySocket *ns = NULL;
g_autoptr(GError) err = NULL;
bolt_autoclose int fd = -1;
NotifySocket *ns = NULL;
static const int one = 1;
struct sockaddr_un sau = {AF_UNIX, {'\0', }};
size_t socklen;
......@@ -158,6 +157,7 @@ notify_socket_free (NotifySocket *ns)
g_clear_pointer (&ns->tmpdir, bolt_tmp_dir_destroy);
g_queue_free_full (&ns->messages, g_free);
g_clear_pointer (&ns->socket_path, g_free);
g_free (ns);
}
......
......@@ -426,6 +426,7 @@ mock_sysfs_force_power_remove (MockSysfs *ms)
umockdev_testbed_uevent (ms->bed, ms->force_power, "remove");
umockdev_testbed_remove_device (ms->bed, ms->force_power);
g_clear_pointer (&ms->force_power, g_free);
return TRUE;
}
......
......@@ -462,6 +462,7 @@ static void
test_wire_conv_enum (TestGlue *tt, gconstpointer data)
{
g_autoptr(BoltWireConv) conv = NULL;
g_autoptr(GParamSpec) spec = NULL;
g_autoptr(GError) err = NULL;
g_autoptr(GVariant) bogus = NULL;
g_autoptr(GVariant) var = NULL;
......@@ -469,7 +470,6 @@ test_wire_conv_enum (TestGlue *tt, gconstpointer data)
const GVariantType *wire_type;
const GParamSpec *prop_spec;
gboolean ok;
GParamSpec *spec;
spec = g_param_spec_enum ("test", "Test",
"Test Enumeration",
......@@ -548,6 +548,7 @@ static void
test_wire_conv_flags (TestGlue *tt, gconstpointer data)
{
g_autoptr(BoltWireConv) conv = NULL;
g_autoptr(GParamSpec) spec = NULL;
g_autoptr(GError) err = NULL;
g_autoptr(GVariant) bogus = NULL;
g_autoptr(GVariant) var = NULL;
......@@ -555,7 +556,6 @@ test_wire_conv_flags (TestGlue *tt, gconstpointer data)
const GVariantType *wire_type;
const GParamSpec *prop_spec;
gboolean ok;
GParamSpec *spec;
spec = g_param_spec_flags ("test", "Test",
"Test Flags",
......@@ -632,6 +632,7 @@ static void
test_wire_conv_object (TestGlue *tt, gconstpointer data)
{
g_autoptr(BoltWireConv) conv = NULL;
g_autoptr(GParamSpec) spec = NULL;
g_autoptr(GError) err = NULL;
g_autoptr(GVariant) bogus = NULL;
g_autoptr(GVariant) var = NULL;
......@@ -639,7 +640,6 @@ test_wire_conv_object (TestGlue *tt, gconstpointer data)
const GVariantType *wire_type;
const GParamSpec *prop_spec;
gboolean ok;
GParamSpec *spec;
spec = g_param_spec_object ("obj", "Obj",
"Object Test",
......@@ -674,6 +674,7 @@ test_wire_conv_object (TestGlue *tt, gconstpointer data)
==,
"");
g_clear_pointer (&var, g_variant_unref);
/* to the wire, value holding a valid object */
g_value_reset (&val);
g_value_set_object (&val, tt->bg);
......@@ -700,11 +701,11 @@ test_wire_conv_simple (TestGlue *tt, gconstpointer data)
g_autoptr(BoltWireConv) conv = NULL;
g_autoptr(GError) err = NULL;
g_autoptr(GVariant) var = NULL;
g_autoptr(GParamSpec) spec = NULL;
g_auto(GValue) val = G_VALUE_INIT;
const GVariantType *wire_type;
const GParamSpec *prop_spec;
gboolean ok;
GParamSpec *spec;
spec = g_param_spec_uint64 ("uint", "Uint",
"Unsigned Integer",
......@@ -769,11 +770,11 @@ static void
test_wire_conv_custom (TestGlue *tt, gconstpointer data)
{
g_autoptr(BoltWireConv) conv = NULL;
g_autoptr(GParamSpec) spec = NULL;
g_autoptr(GError) err = NULL;
g_autoptr(GVariant) var = NULL;
g_auto(GValue) val = G_VALUE_INIT;
gboolean ok;
GParamSpec *spec;
BoltLinkSpeed *check;
BoltLinkSpeed attr =
{.rx.speed = 10,
......
......@@ -418,6 +418,8 @@ test_key (TestStore *tt, gconstpointer user_data)
g_assert_no_error (err);
g_assert_nonnull (loaded);
g_clear_object (&loaded);
/* corrupt the key */
p = g_file_get_path (f);
r = truncate (p, 32);
......
......@@ -205,6 +205,7 @@ test_udev_basic (TestUdev *tt, gconstpointer user)
/* cleanup */
uevent_clear (&ev);
udev_device_unref (dev);
}
static void
......
......@@ -90,6 +90,8 @@ test_watchdog_basic (TestWatchdog *tt, gconstpointer user_data)
/* invalid watchdog env */
g_setenv (BOLT_SD_WATCHDOG_USEC, "INVALID", TRUE);
g_clear_object (&dog);
dog = bolt_watchdog_new (&err);
g_assert_error (err, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
g_assert_null (dog);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment