eolian: prevent freeing of full named structures that are inside of typedefs and fix a memory leak

This commit is contained in:
Daniel Kolesa 2014-07-22 10:39:34 +01:00
parent 71ae2f2c2e
commit ccf157aa57
3 changed files with 28 additions and 22 deletions

View File

@ -6,28 +6,33 @@ void
database_type_del(Eolian_Type *tp) database_type_del(Eolian_Type *tp)
{ {
if (!tp) return; if (!tp) return;
if (tp->type == EOLIAN_TYPE_POINTER || tp->type == EOLIAN_TYPE_FUNCTION) const char *sp;
{ Eolian_Type *stp;
Eolian_Type *stp; if (tp->subtypes) EINA_LIST_FREE(tp->subtypes, stp)
if (tp->subtypes) EINA_LIST_FREE(tp->subtypes, stp) database_type_del(stp);
database_type_del(stp); if (tp->base_type)
if (tp->base_type) database_type_del(tp->base_type);
database_type_del(tp->base_type); if (tp->name) eina_stringshare_del(tp->name);
} if (tp->full_name) eina_stringshare_del(tp->full_name);
else if (tp->fields) eina_hash_free(tp->fields);
{ if (tp->namespaces) EINA_LIST_FREE(tp->namespaces, sp)
const char *sp; eina_stringshare_del(sp);
if (tp->name) eina_stringshare_del(tp->name); if (tp->comment) eina_stringshare_del(tp->comment);
if (tp->full_name) eina_stringshare_del(tp->full_name); if (tp->file) eina_stringshare_del(tp->file);
if (tp->fields) eina_hash_free(tp->fields);
if (tp->namespaces) EINA_LIST_FREE(tp->namespaces, sp)
eina_stringshare_del(sp);
if (tp->comment) eina_stringshare_del(tp->comment);
if (tp->file) eina_stringshare_del(tp->file);
}
free(tp); free(tp);
} }
void
database_typedef_del(Eolian_Type *tp)
{
if (!tp) return;
Eolian_Type *btp = tp->base_type;
/* prevent deletion of named structs as they're deleted later on */
if (btp && btp->type == EOLIAN_TYPE_STRUCT && btp->name)
tp->base_type = NULL;
database_type_del(tp);
}
Eina_Bool Eina_Bool
database_type_add(Eolian_Type *def) database_type_add(Eolian_Type *def)
{ {

View File

@ -15,7 +15,7 @@ database_init()
{ {
if (_database_init_count > 0) return ++_database_init_count; if (_database_init_count > 0) return ++_database_init_count;
eina_init(); eina_init();
_aliases = eina_hash_stringshared_new(EINA_FREE_CB(database_type_del)); _aliases = eina_hash_stringshared_new(EINA_FREE_CB(database_typedef_del));
_structs = eina_hash_stringshared_new(EINA_FREE_CB(database_type_del)); _structs = eina_hash_stringshared_new(EINA_FREE_CB(database_type_del));
_filenames = eina_hash_string_small_new(free); _filenames = eina_hash_string_small_new(free);
_tfilenames = eina_hash_string_small_new(free); _tfilenames = eina_hash_string_small_new(free);

View File

@ -146,8 +146,9 @@ int database_shutdown();
/* types */ /* types */
Eina_Bool database_type_add(Eolian_Type *def); Eina_Bool database_type_add(Eolian_Type *def);
Eina_Bool database_struct_add(Eolian_Type *type); Eina_Bool database_struct_add(Eolian_Type *tp);
void database_type_del(Eolian_Type *type); void database_type_del(Eolian_Type *tp);
void database_typedef_del(Eolian_Type *tp);
void database_type_print(Eolian_Type *type); void database_type_print(Eolian_Type *type);
void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name); void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name);