From d04abdcfbd5d6ab8cf6d32358550dd6af960bf5c Mon Sep 17 00:00:00 2001
From: Thomas Schmitt <scdbackup@gmx.net>
Date: Sat, 10 Oct 2015 11:05:41 +0200
Subject: [PATCH] Closed memory leak with memory shortage while creating
 IsoSymlink object. Coverity CID 12575.

---
 libisofs/builder.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libisofs/builder.c b/libisofs/builder.c
index fd9ce0b..df135d7 100644
--- a/libisofs/builder.c
+++ b/libisofs/builder.c
@@ -106,11 +106,11 @@ static
 int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
                         IsoFileSource *src, char *in_name, IsoNode **node)
 {
-    int ret;
+    int ret, name_is_attached = 0;
     struct stat info;
     IsoNode *new;
     IsoFilesystem *fs;
-    char *name;
+    char *name = NULL;
     unsigned char *aa_string = NULL;
     char *a_text = NULL, *d_text = NULL;
     char *dest = NULL;
@@ -217,10 +217,9 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
         break;
     }
     
-    if (ret < 0) {
-        free(name);
+    if (ret < 0)
         goto ex;
-    }
+    name_is_attached = 1;
 
     /* fill fields */
     iso_node_set_perms_internal(new, info.st_mode, 1);
@@ -263,6 +262,8 @@ int default_create_node(IsoNodeBuilder *builder, IsoImage *image,
 
     ret = ISO_SUCCESS;
 ex:;
+    if (name != NULL && !name_is_attached)
+        free(name);
     LIBISO_FREE_MEM(dest);
     return ret;
 }