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)
{
if (!tp) return;
if (tp->type == EOLIAN_TYPE_POINTER || tp->type == EOLIAN_TYPE_FUNCTION)
{
Eolian_Type *stp;
if (tp->subtypes) EINA_LIST_FREE(tp->subtypes, stp)
database_type_del(stp);
if (tp->base_type)
database_type_del(tp->base_type);
}
else
{
const char *sp;
if (tp->name) eina_stringshare_del(tp->name);
if (tp->full_name) eina_stringshare_del(tp->full_name);
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);
}
const char *sp;
Eolian_Type *stp;
if (tp->subtypes) EINA_LIST_FREE(tp->subtypes, stp)
database_type_del(stp);
if (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);
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);
}
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
database_type_add(Eolian_Type *def)
{

View File

@ -15,7 +15,7 @@ database_init()
{
if (_database_init_count > 0) return ++_database_init_count;
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));
_filenames = eina_hash_string_small_new(free);
_tfilenames = eina_hash_string_small_new(free);

View File

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