jeyzu pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=82b852850fa2643520eb2dc450c047b487b03c0e

commit 82b852850fa2643520eb2dc450c047b487b03c0e
Author: Jérémy Zurcher <[email protected]>
Date:   Fri Jun 6 00:05:06 2014 +0200

    fix memory leak in Eina_Strbuf usage
    
    buf was not freed on error, and never on success
    
    CID 1194715
---
 src/lib/edje/Edje_Edit.h |  2 ++
 src/lib/edje/edje_edit.c | 10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/lib/edje/Edje_Edit.h b/src/lib/edje/Edje_Edit.h
index 4210d77..701f5ca 100644
--- a/src/lib/edje/Edje_Edit.h
+++ b/src/lib/edje/Edje_Edit.h
@@ -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,
diff --git a/src/lib/edje/edje_edit.c b/src/lib/edje/edje_edit.c
index 9d56976..9f2c73a 100644
--- a/src/lib/edje/edje_edit.c
+++ b/src/lib/edje/edje_edit.c
@@ -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

-- 


Reply via email to