[libvirt] [PATCH 4/4] audit: fix memory leak without WITH_AUDIT

Ján Tomko jtomko at redhat.com
Thu Sep 18 10:14:12 UTC 2014


Free str unconditionally since we allocate it without WITH_AUDIT
too.
---
 src/util/viraudit.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/src/util/viraudit.c b/src/util/viraudit.c
index d0ad9b9..23928fd 100644
--- a/src/util/viraudit.c
+++ b/src/util/viraudit.c
@@ -115,12 +115,7 @@ void virAuditSend(virLogSourcePtr source,
     }
 
 #if WITH_AUDIT
-    if (auditfd < 0) {
-        VIR_FREE(str);
-        return;
-    }
-
-    if (str) {
+    if (str && auditfd >= 0) {
         static const int record_types[] = {
             [VIR_AUDIT_RECORD_MACHINE_CONTROL] = AUDIT_VIRT_CONTROL,
             [VIR_AUDIT_RECORD_MACHINE_ID] = AUDIT_VIRT_MACHINE_ID,
@@ -135,9 +130,9 @@ void virAuditSend(virLogSourcePtr source,
             VIR_WARN("Failed to send audit message %s: %s",
                      NULLSTR(str), virStrerror(errno, ebuf, sizeof(ebuf)));
         }
-        VIR_FREE(str);
     }
 #endif
+    VIR_FREE(str);
 }
 
 void virAuditClose(void)
-- 
1.8.5.5




More information about the libvir-list mailing list