[libvirt] [PATCH] util: Fix resource leak

Wang King posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20170412084404.34372-1-king.wang@huawei.com
src/util/virrotatingfile.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[libvirt] [PATCH] util: Fix resource leak
Posted by Wang King 7 years ago
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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util: Fix resource leak
Posted by John Ferlan 7 years ago

On 04/12/2017 04:44 AM, Wang King wrote:
> The virRotatingFileWriterAppend method leaks the file->entry
> on the virRotatingFileWriterEntryNew failing path.
> ---
>  src/util/virrotatingfile.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 

ACK (and will push shortly)

John

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