dwarf_loader: Fix memleaks in creating cus
PATCH v2 1/1 dwarf_loader: Fix memleaks in creating cus
Coverity reports a possible memleak in dwarf_cus__create_cu due to cu not being freed for the case when it was allocated but cu__set_common failed. The same situation occurs in __cus_load_debug_types.
Fix the leaks.
Signed-off-by Viktor Malik <[email protected]>
--- dwarf_loader.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
dwarf_loader.c +7 -2
@@ -3247,11 +3247,14 @@ static int __cus__load_debug_types(struct cus *cus, struct conf_load *conf, Dwfl build_id_len, filename, conf->use_obstack);if (cu ==NULL ||cu__set_common (cu, conf, mod, elf) !=0 ) { +cu__delete (cu);return DWARF_CB_ABORT ; } -if (dwarf_cu__init (dcup, cu) !=0 ) +if (dwarf_cu__init (dcup, cu) !=0 ) { +cu__delete (cu);return DWARF_CB_ABORT ; + } dcup->cu = cu;/* Funny hack. */ dcup->type_unit = dcup;
@@ -3378,8 +3381,10 @@ static struct dwarf_cu *dwarf_cus__create_cu(struct dwarf_cus *dcus, Dwarf_Die **/ const char *name =attr_string (cu_die, DW_AT_name, dcus->conf);struct cu *cu =cu__new (name ?:"" , pointer_size, dcus->build_id, dcus->build_id_len, dcus->filename, dcus->conf->use_obstack); -if (cu ==NULL ||cu__set_common (cu, dcus->conf, dcus->mod, dcus->elf) !=0 ) +if (cu ==NULL ||cu__set_common (cu, dcus->conf, dcus->mod, dcus->elf) !=0 ) { +cu__delete (cu);return NULL ; + }struct dwarf_cu *dcu =dwarf_cu__new (cu);
Signature · 1 line
2.46.0
Quoted 7 lines · Viktor Malik
Coverity reports a possible memleak in
dwarf_cus__create_cudue to cu not being freed for the case when it was allocated butcu__set_commonfailed. The same situation occurs in__cus_load_debug_types.Fix the leaks.
Signed-off-by Viktor Malik <[email protected]>
Reviewed-by Alan Maguire <[email protected]>
Tested-by Alan Maguire <[email protected]>
Thanks!
Quoted 36 lines
--- dwarf_loader.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)dwarf_loader.c +7
-2@@ -3247,11 +3247,14 @@ static int __cus__load_debug_types(struct cus *cus, struct conf_load *conf, Dwfl build_id_len, filename, conf->use_obstack);if (cu ==NULL ||cu__set_common (cu, conf, mod, elf) !=0 ) { +cu__delete (cu);return DWARF_CB_ABORT ; } -if (dwarf_cu__init (dcup, cu) !=0 ) +if (dwarf_cu__init (dcup, cu) !=0 ) { +cu__delete (cu);return DWARF_CB_ABORT ; + } dcup->cu = cu;/* Funny hack. */ dcup->type_unit = dcup;@@ -3378,8 +3381,10 @@ static struct dwarf_cu *dwarf_cus__create_cu(struct dwarf_cus *dcus, Dwarf_Die **/ const char *name =attr_string (cu_die, DW_AT_name, dcus->conf);struct cu *cu =cu__new (name ?:"" , pointer_size, dcus->build_id, dcus->build_id_len, dcus->filename, dcus->conf->use_obstack); -if (cu ==NULL ||cu__set_common (cu, dcus->conf, dcus->mod, dcus->elf) !=0 ) +if (cu ==NULL ||cu__set_common (cu, dcus->conf, dcus->mod, dcus->elf) !=0 ) { +cu__delete (cu);return NULL ; + }struct dwarf_cu *dcu =dwarf_cu__new (cu);