diff mbox series

[1/2] rpcb_clnt.c: fix a possible double free

Message ID 20230801093310.594942-2-yoyang@redhat.com (mailing list archive)
State New, archived
Headers show
Series Double-Free and Memory Leak Found In libtirpc | expand

Commit Message

Yongcheng Yang Aug. 1, 2023, 9:33 a.m. UTC
Signed-off-by: Herb Wartens <wartens2@llnl.gov>
---
 src/rpcb_clnt.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/src/rpcb_clnt.c b/src/rpcb_clnt.c
index d178d86..630f9ad 100644
--- a/src/rpcb_clnt.c
+++ b/src/rpcb_clnt.c
@@ -252,12 +252,16 @@  delete_cache(addr)
 	for (cptr = front; cptr != NULL; cptr = cptr->ac_next) {
 		if (!memcmp(cptr->ac_taddr->buf, addr->buf, addr->len)) {
 			/* Unlink from cache. We'll destroy it after releasing the mutex. */
-			if (cptr->ac_uaddr)
+			if (cptr->ac_uaddr) {
 				free(cptr->ac_uaddr);
-			if (prevptr)
+				cptr->ac_uaddr = NULL;
+			}
+			if (prevptr) {
 				prevptr->ac_next = cptr->ac_next;
-			else
+			}
+			else {
 				front = cptr->ac_next;
+			}
 			cachesize--;
 			break;
 		}