Skip to contentSkip to conversation

Fix Valgrind errors

PATCH In review Ossama Othman 2 participants 5 messages Dec 18, 2021 – Dec 20, 2021

lore
Share & tools
lore
#0 lore raw

cover Fix Valgrind errors

Running the ELL test suite through Valgrind triggers a few errors. This set of patches addresses three of those errors.

Ossama Othman (3):
dhcp-server: Fix memory leak.
unit: Free l_uintset when done.
unit: Initialize variables prior to use

 ell/dhcp-server.c   | 1 +
 unit/test-rtnl.c    | 2 +-
 unit/test-uintset.c | 2 ++
 3 files changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/3 dhcp-server: Fix memory leak.

When adding a lease, free the dns field of a l_dhcp_lease instance prior to updating it. This addresses a memory leak found when running the test-dhcp unit test through the Valgrind memcheck tool.

---
 ell/dhcp-server.c | 1 +
 1 file changed, 1 insertion(+)
ell/dhcp-server.c +1 -0
index c8b06a6..ff0784f 100644
@@ -308,6 +308,7 @@ static struct l_dhcp_lease *add_lease(struct l_dhcp_server *server,
 	if (ret != 0)
 		return NULL;
 
+	l_free(lease->dns);
 	l_free(lease->client_id);
 	memset(lease, 0, sizeof(*lease));
 
Signature · 1 line
2.32.0
#2 lore raw

PATCH 2/3 unit: Free l_uintset when done.

In reply to Ossama Othman

In the test_uintset_size() test case, free the l_uintset instance when done to fix a memory leak.

---
 unit/test-uintset.c | 2 ++
 1 file changed, 2 insertions(+)
unit/test-uintset.c +2 -0
index 31dc274..6e3767b 100644
@@ -384,6 +384,8 @@ static void test_uintset_size(const void *user_data)
 		assert(l_uintset_take(set, i));
 
 	assert(l_uintset_size(set) == 0);
+
+	l_uintset_free(set);
 }
 
 int main(int argc, char *argv[])
Signature · 1 line
2.32.0
#3 lore raw

PATCH 3/3 unit: Initialize variables prior to use

In reply to Ossama Othman

Address "use of uninitialized variable" related error exhibited by Valgrind in the test-rtnl unit test.

---
 unit/test-rtnl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
unit/test-rtnl.c +1 -1
index 107f69a..e6d2201 100644
@@ -147,7 +147,7 @@ static void route6_dump_cb(int error,
 {
 	const struct rtmsg *rtmsg = data;
 	char *dst = NULL, *gateway = NULL, *src = NULL;
-	uint32_t table, ifindex;
+	uint32_t table = 0, ifindex = 0;
 
 	test_assert(!error);
 	test_assert(type == RTM_NEWROUTE);
Signature · 1 line
2.32.0
#4 lore raw
In reply to Ossama Othman

Hi Ossama,

Quoted 8 lines · Ossama Othman

Running the ELL test suite through Valgrind triggers a few errors. This set of patches addresses three of those errors.

Ossama Othman (3):
dhcp-server: Fix memory leak.
unit: Free l_uintset when done.
unit: Initialize variables prior to use

All applied, thanks.

Regards,
-Denis