From 15753e93d2eec19e08168e6d049abaa94fbb8d19 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 18 Apr 2018 19:57:41 +0200 Subject: 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 --- src/socket.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index d96f664d..cd73f17c 100644 --- a/src/socket.c +++ b/src/socket.c @@ -543,10 +543,13 @@ int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen) 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; } -- cgit v1.2.3