eldbus: codegen: free allocated strbuf in error path
authorStefan Schmidt <stefan@osg.samsung.com>
Thu, 20 Jul 2017 14:15:32 +0000 (16:15 +0200)
committerStefan Schmidt <stefan@osg.samsung.com>
Thu, 20 Jul 2017 14:15:32 +0000 (16:15 +0200)
fname would have been leaked if we failed to get a file_handler.
Also make sure we always create a new fname strbuf even without
a output_dir present to fix a potential unbalance between creating
and freeing.

CID: 1378112

src/bin/eldbus/utils.c

index aaad290..ae1f493 100644 (file)
@@ -37,9 +37,10 @@ file_write(const char *file_name, const char *buffer)
    const char *filename = file_name;
    Eina_Strbuf *fname = NULL;
 
+   fname = eina_strbuf_new();
+
    if (output_dir)
      {
-        fname = eina_strbuf_new();
         eina_strbuf_append_printf(fname, "%s/%s", output_dir, file_name);
         filename = eina_strbuf_string_get(fname);
      }
@@ -47,6 +48,7 @@ file_write(const char *file_name, const char *buffer)
    if (!file_handler)
      {
         printf("Error to write file: %s\n", file_name);
+        eina_strbuf_free(fname);
         return EINA_FALSE;
      }