[libvirt PATCH v2 04/20] commandhelper: Consolidate error paths

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

 



Preparation for later conversion to g_auto* memory handling.

Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/commandhelper.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 22835302b8..1ee697498c 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -71,7 +71,7 @@ int main(int argc, char **argv) {
     ssize_t got;
 
     if (!log)
-        return ret;
+        goto cleanup;
 
     for (i = 1; i < argc; i++) {
         fprintf(log, "ARG:%s\n", argv[i]);
@@ -89,7 +89,7 @@ int main(int argc, char **argv) {
     }
 
     if (!(newenv = malloc(sizeof(*newenv) * n)))
-        abort();
+        goto cleanup;
 
     for (i = 0; i < n; i++) {
         newenv[i] = environ[i];
@@ -232,8 +232,10 @@ int main(int argc, char **argv) {
  cleanup:
     for (i = 0; i < G_N_ELEMENTS(buffers); i++)
         free(buffers[i]);
-    fclose(log);
-    free(newenv);
+    if (newenv)
+        free(newenv);
+    if (log)
+        fclose(log);
     return ret;
 }
 
-- 
2.26.2




[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