Skip to contentSkip to conversation

rpcbind: fix a few memory leaks

PATCH In review Scott Mayhew 2 participants 5 messages May 21 – May 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover rpcbind: fix a few memory leaks

Fix a handful of leaks reported by valgrind.

Scott Mayhew (3):
rpcbind: fix memory leak in init_transport()
rpcbind: fix memory leaks in network_init()
rpcbind: fix memory leak in read_warmstart()

 src/rpcbind.c   | 4 ++++
 src/util.c      | 3 +++
 src/warmstart.c | 3 +++
 3 files changed, 10 insertions(+)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/3 rpcbind: fix memory leak in init_transport()

Once a service registration has been added to list_rbl via rbllist_add(), we no longer need the value stored in taddr.addr.buf. Free it before we leave init_transport(). Fixes memory leaks such as:

==8754== 19 bytes in 1 blocks are definitely lost in loss record 28 of 93

==8754==    at 0x484C826: malloc (vg_replace_malloc.c:447)
==8754==    by 0x40AAD3: init_transport.isra.0 (rpcbind.c:726)
==8754==    by 0x405CB8: main (rpcbind.c:284)
---
 src/rpcbind.c | 4 ++++
 1 file changed, 4 insertions(+)
src/rpcbind.c +4 -0
index bf7b499..4212377 100644
@@ -893,10 +893,14 @@ got_socket:
 
 	if (res != NULL)
 		freeaddrinfo(res);
+	if (taddr.addr.buf != NULL)
+		free(taddr.addr.buf);
 	return (0);
 error:
 	if (res != NULL)
 		freeaddrinfo(res);
+	if (taddr.addr.buf != NULL)
+		free(taddr.addr.buf);
 	close(fd);
 	return (1);
 }
Signature · 1 line
2.54.0
#2 lore raw

PATCH 2/3 rpcbind: fix memory leaks in network_init()

In reply to Scott Mayhew

1. Before reusing res in another getaddrinfo() call, we need to free the previous value stored there. Fixes memory leaks such as:

==8754== 128 (64 direct, 64 indirect) bytes in 1 blocks are definitely lost in loss record 68 of 93

==8754==    at 0x484C826: malloc (vg_replace_malloc.c:447)
==8754==    by 0x4B7C296: generate_addrinfo (getaddrinfo.c:1090)
==8754==    by 0x4B7C296: gaih_inet (getaddrinfo.c:1208)
==8754==    by 0x4B7C296: getaddrinfo (getaddrinfo.c:2387)
==8754==    by 0x40BF9D: network_init (util.c:316)
==8754==    by 0x405E1D: main (rpcbind.c:361)

2. getifaddrs() needs to be paired with freeifaddrs(). Fixes memory leaks such as:

==8754== 1,296 bytes in 1 blocks are definitely lost in loss record 89 of 93

==8754==    at 0x485436B: calloc (vg_replace_malloc.c:1616)
==8754==    by 0x4B5D0BD: getifaddrs_internal (ifaddrs.c:405)
==8754==    by 0x4B5E357: getifaddrs (ifaddrs.c:831)
==8754==    by 0x40BFEF: network_init (util.c:347)
==8754==    by 0x405E1D: main (rpcbind.c:361)
---
 src/util.c | 3 +++
 1 file changed, 3 insertions(+)
src/util.c +3 -0
index 4af8b9b..ead4899 100644
@@ -328,6 +328,7 @@ network_init()
 
 #ifdef INET6
 	hints.ai_family = AF_INET6;
+	freeaddrinfo(res);
 	if ((ecode = getaddrinfo(NULL, "sunrpc", &hints, &res))) {
 		if (debugging)
 			fprintf(stderr, "can't get local ip6 address: %s\n",
@@ -355,6 +356,7 @@ network_init()
 	if (s < 0) {
 	    if (debugging)
 		    fprintf(stderr, "socket(AF_INET6) failed: %s\n", strerror(errno));
+	    freeifaddrs(ifp);
 	    freeaddrinfo (res);
 	    return;
 	}
@@ -381,6 +383,7 @@ network_init()
 				perror("setsockopt v6 multicast");
 	}
 	close(s);
+	freeifaddrs(ifp);
 #endif
 	freeaddrinfo (res);
 }
Signature · 1 line
2.54.0
#3 lore raw

PATCH 3/3 rpcbind: fix memory leak in read_warmstart()

In reply to Scott Mayhew

struct rpcblist contains a struct rpcb, which has pointers to 3 strings. We need to free those before freeing the struct rpcblist or we leak memory. Fixes memory leaks such as:

==8754== 56 bytes in 12 blocks are definitely lost in loss record 54 of 93

==8754==    at 0x485436B: calloc (vg_replace_malloc.c:1616)
==8754==    by 0x4884CD6: xdr_string (xdr.c:808)
==8754==    by 0x4884D50: xdr_rpcb (rpcb_prot.c:57)
==8754==    by 0x488591C: xdr_reference (xdr_reference.c:88)
==8754==    by 0x4885A3F: xdr_rpcblist_ptr (rpcb_prot.c:123)
==8754==    by 0x40C2E0: read_struct (warmstart.c:122)
==8754==    by 0x40C6C9: read_warmstart (warmstart.c:190)
==8754==    by 0x40606F: main (rpcbind.c:357)
---
 src/warmstart.c | 3 +++
 1 file changed, 3 insertions(+)
src/warmstart.c +3 -0
index 8ecd933..b845369 100644
@@ -205,6 +205,9 @@ read_warmstart()
 				*tail = pos;
 				tail = &pos->rpcb_next;
 			} else {
+				free(pos->rpcb_map.r_netid);
+				free(pos->rpcb_map.r_addr);
+				free(pos->rpcb_map.r_owner);
 				free(pos);
 			}
 		}
Signature · 1 line
2.54.0
#4 lore raw
In reply to Scott Mayhew
Quoted 7 lines · Scott Mayhew

Fix a handful of leaks reported by valgrind.

Scott Mayhew (3):
rpcbind: fix memory leak in init_transport()
rpcbind: fix memory leaks in network_init()
rpcbind: fix memory leak in read_warmstart()

Quoted 5 lines
  src/rpcbind.c   | 4 ++++
  src/util.c      | 3 +++
  src/warmstart.c | 3 +++
  3 files changed, 10 insertions(+)

Committed...(tag: rpcbind-1_2_9-rc1)'

steved.