From 63f3b9e883231ca08cf9c3cd8f5d582584412d94 Mon Sep 17 00:00:00 2001
From: Ali Abdallah <ali.abdallah@suse.com>
Date: Thu, 14 Jul 2022 13:47:32 -0400
Subject: [PATCH] Fix potential memory leak of parms.r_addr

During some valgrind test, the following is observed

==11391== 64 bytes in 4 blocks are definitely lost in loss record 11 of 16
==11391==    at 0x4C2A2AF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11391==    by 0x50ECED9: strdup (in /lib64/libc-2.22.so)
==11391==    by 0x4E4AFBF: getclnthandle (in /lib64/libtirpc.so.3.0.0)
==11391==    by 0x4E4BD8A: __rpcb_findaddr_timed (in /lib64/libtirpc.so.3.0.0)
==11391==    by 0x4E443AF: clnt_tp_create_timed (in /lib64/libtirpc.so.3.0.0)
==11391==    by 0x4E44580: clnt_create_timed (in /lib64/libtirpc.so.3.0.0)
==11391==    by 0x400755: main (in /local/02/xdtadti/tirpc-test/client)

Signed-off-by: Steve Dickson <steved@redhat.com>
---
 INSTALL         | 369 +-------------------------------------------------------
 src/rpcb_clnt.c |   8 ++
 2 files changed, 9 insertions(+), 368 deletions(-)
 mode change 100644 => 120000 INSTALL

diff --git a/src/rpcb_clnt.c b/src/rpcb_clnt.c
index 0c34cb7..1a23cb1 100644
--- a/src/rpcb_clnt.c
+++ b/src/rpcb_clnt.c
@@ -798,6 +798,10 @@ __try_protocol_version_2(program, version, nconf, host, tp)
 	pmapaddress->len = pmapaddress->maxlen = remote.len;
 
 	CLNT_DESTROY(client);
+
+	if (parms.r_addr != NULL && parms.r_addr != nullstring)
+		free(parms.r_addr);
+
 	return pmapaddress;
 
 error:
@@ -806,6 +810,10 @@ error:
 		client = NULL;
 
 	}
+
+	if (parms.r_addr != NULL && parms.r_addr != nullstring)
+		free(parms.r_addr);
+
 	return (NULL);
 
 }
-- 
1.8.3.1

