From a046f3459095c8a8993713b25a15e422d3340746 Mon Sep 17 00:00:00 2001 From: Daniel Zaoui Date: Fri, 18 Apr 2014 09:21:35 +0300 Subject: [PATCH] Eolian/Lexer: Fix coverity issues. Fix CID 1203411 Fix CID 1203412 --- src/lib/eolian/eo_lexer.c | 13 +++++++++---- src/lib/eolian/eo_lexer.rl | 13 +++++++++---- src/lib/eolian/eolian_database.c | 18 ++++++++++++------ src/lib/eolian/eolian_database.h | 2 ++ 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c index 2a29144..739fc0f 100644 --- a/src/lib/eolian/eo_lexer.c +++ b/src/lib/eolian/eo_lexer.c @@ -4360,7 +4360,7 @@ _types_extract(const char *buf, int len) if (depth < 0) { ERR("%s: Cannot reopen < after >", save_buf); - return NULL; + goto error; } depth++; end_type = EINA_TRUE; @@ -4371,12 +4371,12 @@ _types_extract(const char *buf, int len) if (depth == 0) { ERR("%s: Too much >", save_buf); - return NULL; + goto error; } if (d == tmp_type) { ERR("%s: empty type inside <>", save_buf); - return NULL; + goto error; } if (depth > 0) depth *= -1; depth++; @@ -4400,9 +4400,14 @@ _types_extract(const char *buf, int len) } if (depth) { - types = NULL; ERR("%s: < and > are not well used.", save_buf); + goto error; } + goto success; +error: + database_type_del(types); + types = NULL; +success: free(tmp_type); return types; } diff --git a/src/lib/eolian/eo_lexer.rl b/src/lib/eolian/eo_lexer.rl index a753300..b36b460 100644 --- a/src/lib/eolian/eo_lexer.rl +++ b/src/lib/eolian/eo_lexer.rl @@ -1330,7 +1330,7 @@ _types_extract(const char *buf, int len) if (depth < 0) { ERR("%s: Cannot reopen < after >", save_buf); - return NULL; + goto error; } depth++; end_type = EINA_TRUE; @@ -1341,12 +1341,12 @@ _types_extract(const char *buf, int len) if (depth == 0) { ERR("%s: Too much >", save_buf); - return NULL; + goto error; } if (d == tmp_type) { ERR("%s: empty type inside <>", save_buf); - return NULL; + goto error; } if (depth > 0) depth *= -1; depth++; @@ -1370,9 +1370,14 @@ _types_extract(const char *buf, int len) } if (depth) { - types = NULL; ERR("%s: < and > are not well used.", save_buf); + goto error; } + goto success; +error: + database_type_del(types); + types = NULL; +success: free(tmp_type); return types; } diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c index 30ac8db..cb815fe 100644 --- a/src/lib/eolian/eolian_database.c +++ b/src/lib/eolian/eolian_database.c @@ -108,16 +108,22 @@ _param_del(_Parameter_Desc *pdesc) { eina_stringshare_del(pdesc->name); - while (pdesc->type) - { - _Parameter_Type *type = (_Parameter_Type *) pdesc->type; - eina_stringshare_del(type->name); - pdesc->type = eina_inlist_remove(pdesc->type, EINA_INLIST_GET(type)); - } + database_type_del(pdesc->type); eina_stringshare_del(pdesc->description); free(pdesc); } +void +database_type_del(Eolian_Type type) +{ + while (type) + { + _Parameter_Type *ptype = (_Parameter_Type *) type; + eina_stringshare_del(ptype->name); + type = eina_inlist_remove(type, EINA_INLIST_GET(ptype)); + } +} + static void _fid_del(_Function_Id *fid) { diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h index 106ffea..82e9a3a 100644 --- a/src/lib/eolian/eolian_database.h +++ b/src/lib/eolian/eolian_database.h @@ -88,6 +88,8 @@ Eolian_Function_Parameter database_method_parameter_add(Eolian_Function foo_id, Eolian_Type database_type_append(Eolian_Type types, const char *name, Eina_Bool own); +void database_type_del(Eolian_Type type); + void database_parameter_const_attribute_set(Eolian_Function_Parameter param_desc, Eina_Bool is_get, Eina_Bool is_const); void database_parameter_nonull_set(Eolian_Function_Parameter, Eina_Bool nonull); -- 2.7.4