Skip to contentSkip to conversation

rpcbind: fix leak of nconf in main()

PATCH In review Scott Mayhew 2 participants 2 messages Jun 30 – Jul 1

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

PATCH 1/1 rpcbind: fix leak of nconf in main()

Before reusing nconf in the getnetconfig() loop, we need to free the memory that was previously allocated via getnetconfigent(). Fixes the following leak reported by valgrind:

==9031== 1,136 (136 direct, 1,000 indirect) bytes in 1 blocks are definitely lost in loss record 63 of 67

==9031==    at 0x485183E: malloc (vg_replace_malloc.c:447)
==9031==    by 0x4879D1F: getnetconfigent (in /usr/lib64/libtirpc.so.3.0.0)
==9031==    by 0x4004336: main (rpcbind.c:271)
---
 src/rpcbind.c | 1 +
 1 file changed, 1 insertion(+)
src/rpcbind.c +1 -0
index 4212377..c39df97 100644
@@ -282,6 +282,7 @@ main(int argc, char *argv[])
 	rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
 
 	init_transport(nconf);
+	freenetconfigent(nconf);
 
 	while ((nconf = getnetconfig(nc_handle))) {
 		if (nconf->nc_flag & NC_VISIBLE)
Signature · 1 line
2.54.0
#1 lore raw
Quoted 10 lines · Scott Mayhew

Before reusing nconf in the getnetconfig() loop, we need to free the memory that was previously allocated via getnetconfigent(). Fixes the following leak reported by valgrind:

==9031== 1,136 (136 direct, 1,000 indirect) bytes in 1 blocks are definitely lost in loss record 63 of 67

==9031==    at 0x485183E: malloc (vg_replace_malloc.c:447)
==9031==    by 0x4879D1F: getnetconfigent (in /usr/lib64/libtirpc.so.3.0.0)
==9031==    by 0x4004336: main (rpcbind.c:271)

Committed...

steved.> ---

Quoted 15 lines
  src/rpcbind.c | 1 +
  1 file changed, 1 insertion(+)
src/rpcbind.c +1 -0
index 4212377..c39df97 100644
@@ -282,6 +282,7 @@ main(int argc, char *argv[])
  	rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
 
  	init_transport(nconf);
+	freenetconfigent(nconf);
 
  	while ((nconf = getnetconfig(nc_handle))) {
  		if (nconf->nc_flag & NC_VISIBLE)