[PATCH] libosmocore[master]: osmo_sockaddr_is_local: Fix memleak

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Wed Apr 18 17:59:05 UTC 2018


Review at  https://gerrit.osmocom.org/7872

osmo_sockaddr_is_local: Fix memleak

Catched by AddressSanitizer in osmo-bts-trx while running tests in
osmo-gsm-tester:

==31738==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 5744 byte(s) in 1 object(s) allocated from:
    #0 0x7ff7ec789ed0 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1ed0)
    #1 0x7ff7e952697c  (/lib/x86_64-linux-gnu/libc.so.6+0x10297c)
    #2 0x7ff7e95274df in getifaddrs (/lib/x86_64-linux-gnu/libc.so.6+0x1034df)
    #3 0x7ff7eadcdc8f in osmo_sockaddr_is_local libosmocore/src/socket.c:537

Change-Id: I778d3c1f162abce0595e62670c29c5134bccd28d
---
M src/socket.c
1 file changed, 4 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/72/7872/1

diff --git a/src/socket.c b/src/socket.c
index d96f664..cd73f17 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -543,10 +543,13 @@
 	for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
 		if (!ifa->ifa_addr)
 			continue;
-		if (sockaddr_equal(ifa->ifa_addr, addr, addrlen))
+		if (sockaddr_equal(ifa->ifa_addr, addr, addrlen)) {
+			freeifaddrs(ifaddr);
 			return 1;
+		}
 	}
 
+	freeifaddrs(ifaddr);
 	return 0;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/7872
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I778d3c1f162abce0595e62670c29c5134bccd28d
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>



More information about the gerrit-log mailing list