From: Jérémy Zurcher Date: Thu, 5 Jun 2014 22:05:06 +0000 (+0200) Subject: fix memory leak in Eina_Strbuf usage X-Git-Tag: upstream/1.10.0+1149+ga3a15b1~678 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=82b852850fa2643520eb2dc450c047b487b03c0e;p=platform%2Fupstream%2Fefl.git fix memory leak in Eina_Strbuf usage buf was not freed on error, and never on success CID 1194715 --- 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