[PATCH] util: Fix resource leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The virRotatingFileWriterAppend method leaks the file->entry
on the virRotatingFileWriterEntryNew failing path.
---
 src/util/virrotatingfile.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/util/virrotatingfile.c b/src/util/virrotatingfile.c
index 9144729..83a695f 100644
--- a/src/util/virrotatingfile.c
+++ b/src/util/virrotatingfile.c
@@ -483,18 +483,19 @@ virRotatingFileWriterAppend(virRotatingFileWriterPtr file,
 
         if ((file->entry->pos == file->maxlen && len) ||
             forceRollover) {
-            virRotatingFileWriterEntryPtr tmp = file->entry;
+            virRotatingFileWriterEntryPtr tmp;
             VIR_DEBUG("Hit max size %zu on %s (force=%d)\n",
                       file->maxlen, file->basepath, forceRollover);
 
             if (virRotatingFileWriterRollover(file) < 0)
                 return -1;
 
-            if (!(file->entry = virRotatingFileWriterEntryNew(file->basepath,
-                                                              file->mode)))
+            if (!(tmp = virRotatingFileWriterEntryNew(file->basepath,
+                                                      file->mode)))
                 return -1;
 
-            virRotatingFileWriterEntryFree(tmp);
+            virRotatingFileWriterEntryFree(file->entry);
+            file->entry = tmp;
         }
     }
 
-- 
2.8.3


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux