[libgovirt] proxy: Fix leaks in write_to_tmp_file()



commit 9ec14da6685281c01ab45969391eaba38f5aa298
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Mon Jul 27 12:02:31 2015 +0200

    proxy: Fix leaks in write_to_tmp_file()
    
    The GIOStream returned by g_file_new_tmp is (transfer full), so it must
    be unref'ed when no longer needed. An early return would cause the new
    GFile instance from g_file_new_tmp to not be unref'ed on success.

 govirt/ovirt-proxy.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/govirt/ovirt-proxy.c b/govirt/ovirt-proxy.c
index c6cc519..29fd6c6 100644
--- a/govirt/ovirt-proxy.c
+++ b/govirt/ovirt-proxy.c
@@ -457,7 +457,7 @@ static char *write_to_tmp_file(const char *template,
                                GError **error)
 {
     GFile *tmp_file = NULL;
-    GFileIOStream *iostream;
+    GFileIOStream *iostream = NULL;
     GOutputStream *output;
     gboolean write_ok;
     char *result = NULL;
@@ -474,12 +474,15 @@ static char *write_to_tmp_file(const char *template,
         goto end;
     }
 
-    return g_file_get_path(tmp_file);
+    result = g_file_get_path(tmp_file);
 
 end:
     if (tmp_file != NULL) {
         g_object_unref(G_OBJECT(tmp_file));
     }
+    if (iostream != NULL) {
+        g_object_unref(G_OBJECT(iostream));
+    }
 
     return result;
 }



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