From 9de5f0c13684cfeb73b9503dd426a0f4e01d32cc Mon Sep 17 00:00:00 2001 From: cedric Date: Thu, 12 Aug 2010 15:05:56 +0000 Subject: [PATCH] * edje: fix memory leak. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/edje@51046 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/edje_cc_out.c | 18 ++++++++++++++++++ src/bin/edje_convert.c | 7 +++++-- src/lib/edje_cache.c | 7 +++++-- src/lib/edje_data.c | 18 +++++++++--------- src/lib/edje_load.c | 19 ++++++++++++++++++- 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/bin/edje_cc_out.c b/src/bin/edje_cc_out.c index 82cd111..2296ffe 100644 --- a/src/bin/edje_cc_out.c +++ b/src/bin/edje_cc_out.c @@ -237,8 +237,26 @@ data_write_header(Eet_File *ef) /* copy aliases into collection directory */ EINA_LIST_FREE(aliases, ce) { + Edje_Part_Collection_Directory_Entry *sce; + Eina_Iterator *it; + if (!ce->entry) error_and_abort(ef, "Collection %i: name missing.\n", ce->id); + + it = eina_hash_iterator_data_new(new_edje_file->collection); + + EINA_ITERATOR_FOREACH(it, sce) + if (ce->id == sce->id) + { + memcpy(&ce->count, &sce->count, sizeof (ce->count)); + break; + } + + if (!sce) + error_and_abort(ef, "Collection %s (%i) can't find an correct alias.\n", ce->entry, ce->id); + + eina_iterator_free(it); + eina_hash_direct_add(new_edje_file->collection, ce->entry, ce); } } diff --git a/src/bin/edje_convert.c b/src/bin/edje_convert.c index 07f234a..3d3aa81 100644 --- a/src/bin/edje_convert.c +++ b/src/bin/edje_convert.c @@ -204,6 +204,7 @@ _edje_collection_convert(Eet_File *ef, Edje_Part_Collection_Directory_Entry *ce, Edje_Program *pg; Old_Edje_Data *di; Eina_List *l; + char *buffer; unsigned int k; oedc->part = ce->entry; @@ -240,8 +241,10 @@ _edje_collection_convert(Eet_File *ef, Edje_Part_Collection_Directory_Entry *ce, } ce->count.part = eina_list_count(oedc->parts); -#define CONVERT_EMN(Tp, Sz, Ce) \ - Ce->mp.Tp = eina_mempool_add("one_big", #Tp, NULL, sizeof (Sz), Ce->count.Tp); +#define CONVERT_EMN(Tp, Sz, Ce) \ + buffer = alloca(strlen(ce->entry) + strlen(#Tp) + 2); \ + sprintf(buffer, "%s/%s", ce->entry, #Tp); \ + Ce->mp.Tp = eina_mempool_add("one_big", buffer, NULL, sizeof (Sz), Ce->count.Tp); CONVERT_EMN(RECTANGLE, Edje_Part_Description_Common, ce); CONVERT_EMN(TEXT, Edje_Part_Description_Text, ce); diff --git a/src/lib/edje_cache.c b/src/lib/edje_cache.c index db5d7c5..17ec332 100644 --- a/src/lib/edje_cache.c +++ b/src/lib/edje_cache.c @@ -63,6 +63,7 @@ _edje_file_coll_open(Edje_File *edf, const char *coll) int id = -1, size = 0; Eina_List *l; char buf[256]; + char *buffer; void *data; ce = eina_hash_find(edf->collection, coll); @@ -89,8 +90,10 @@ _edje_file_coll_open(Edje_File *edf, const char *coll) id = ce->id; if (id < 0) return NULL; -#define INIT_EMP(Tp, Sz, Ce) \ - Ce->mp.Tp = eina_mempool_add("one_big", #Tp, NULL, sizeof (Sz), Ce->count.Tp); \ +#define INIT_EMP(Tp, Sz, Ce) \ + buffer = alloca(strlen(ce->entry) + strlen(#Tp) + 2); \ + sprintf(buffer, "%s/%s", ce->entry, #Tp); \ + Ce->mp.Tp = eina_mempool_add("one_big", buffer, NULL, sizeof (Sz), Ce->count.Tp); \ _emp_##Tp = Ce->mp.Tp; INIT_EMP(RECTANGLE, Edje_Part_Description_Common, ce); diff --git a/src/lib/edje_data.c b/src/lib/edje_data.c index f901367..010c207 100644 --- a/src/lib/edje_data.c +++ b/src/lib/edje_data.c @@ -279,15 +279,15 @@ _edje_edd_init(void) EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "entry", entry, EET_T_STRING); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "id", id, EET_T_INT); EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.RECTANGLE", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.TEXT", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.IMAGE", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.SWALLOW", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.TEXTBLOCK", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.GROUP", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.BOX", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.TABLE", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.EXTERNAL", count.RECTANGLE, EET_T_INT); - EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.part", count.RECTANGLE, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.TEXT", count.TEXT, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.IMAGE", count.IMAGE, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.SWALLOW", count.SWALLOW, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.TEXTBLOCK", count.TEXTBLOCK, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.GROUP", count.GROUP, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.BOX", count.BOX, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.TABLE", count.TABLE, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.EXTERNAL", count.EXTERNAL, EET_T_INT); + EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_collection_directory_entry, Edje_Part_Collection_Directory_Entry, "count.part", count.part, EET_T_INT); EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Style_Tag); _edje_edd_edje_style_tag = diff --git a/src/lib/edje_load.c b/src/lib/edje_load.c index a1731de..4d2acfd 100644 --- a/src/lib/edje_load.c +++ b/src/lib/edje_load.c @@ -1120,6 +1120,12 @@ _edje_file_free(Edje_File *edf) free(edf->image_dir); } + if (edf->external_dir) + { + if (edf->external_dir->entries) free(edf->external_dir->entries); + free(edf->external_dir); + } + EINA_LIST_FREE(edf->color_classes, ecc) { if (edf->free_strings && ecc->name) eina_stringshare_del(ecc->name); @@ -1197,7 +1203,18 @@ _edje_collection_free(Edje_File *edf, Edje_Part_Collection *ec, Edje_Part_Collec free(ec->parts); ec->parts = NULL; - if (ec->data) eina_hash_free(ec->data); + if (ec->data) + { + Eina_Iterator *it; + Edje_String *es; + + it = eina_hash_iterator_data_new(ec->data); + EINA_ITERATOR_FOREACH(it, es) + free(es); + eina_iterator_free(it); + + eina_hash_free(ec->data); + } #ifdef EDJE_PROGRAM_CACHE if (ec->prog_cache.no_matches) eina_hash_free(ec->prog_cache.no_matches); if (ec->prog_cache.matches) -- 2.7.4