[libvirt PATCH 2/2] nss: findLease: do not leak path

Ján Tomko jtomko at redhat.com
Mon Mar 15 15:46:08 UTC 2021


We still check for realloc's return value in the nss module.

Free the path in case it fails before jumping to cleanup.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 tools/nss/libvirt_nss.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index b021efc3c9..87a731da79 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -138,8 +138,10 @@ findLease(const char *name,
                 goto cleanup;
 
             tmpLease = realloc(leaseFiles, sizeof(char *) * (nleaseFiles + 1));
-            if (!tmpLease)
+            if (!tmpLease) {
+                free(path);
                 goto cleanup;
+            }
             leaseFiles = tmpLease;
             leaseFiles[nleaseFiles++] = path;
 #if defined(LIBVIRT_NSS_GUEST)
-- 
2.29.2




More information about the libvir-list mailing list