fix memory leak in Eina_Strbuf usage
authorJérémy Zurcher <jeremy@asynk.ch>
Thu, 5 Jun 2014 22:05:06 +0000 (00:05 +0200)
committerJérémy Zurcher <jeremy@asynk.ch>
Thu, 5 Jun 2014 22:13:11 +0000 (00:13 +0200)
buf was not freed on error, and never on success

CID 1194715

src/lib/edje/Edje_Edit.h
src/lib/edje/edje_edit.c

index 4210d77..701f5ca 100644 (file)
@@ -4362,6 +4362,8 @@ EAPI const Eina_List *edje_edit_script_error_list_get(Evas_Object *obj);
 /**
  * Return source code of the current edje edit object.
  *
+ * Remember to free the string with edje_edit_string_free()
+ *
  * This function will return source code of the whole group, loaded previously.
  * This function also will collect all possible resources that is required and
  * mentioned in description blocks. For example: all images, fonts, data, styles,
index 9d56976..9f2c73a 100644 (file)
@@ -7534,7 +7534,8 @@ edje_edit_source_generate(Evas_Object *obj)
    Edje_Part_Description_Text *part_desc_text;
    unsigned int i, j;
    const char *entry;
-   Eina_Strbuf *buf = eina_strbuf_new();
+   const char *str;
+   Eina_Strbuf *buf = NULL;
    Eina_Bool ret = EINA_TRUE;
    Eina_List *images = NULL, *color_classes = NULL, *styles = NULL, *fonts = NULL;
    Eina_List *l;
@@ -7602,6 +7603,8 @@ edje_edit_source_generate(Evas_Object *obj)
           }
      }
 
+   buf = eina_strbuf_new();
+
    /* if images were found, print them */
    if (images)
      {
@@ -7659,11 +7662,14 @@ edje_edit_source_generate(Evas_Object *obj)
    if (!ret)
      {
         ERR("Generating EDC for This Group.");
+        eina_strbuf_free(buf);
         return NULL;
      }
 
    /* return resulted source code of the group */
-   return eina_strbuf_string_get(buf);
+   str = eina_stringshare_add(eina_strbuf_string_get(buf));
+   eina_strbuf_free(buf);
+   return str;
 }
 
 #undef COLLECT_RESOURCE