[PATCH dwarves] dwarf_loader: Fix memleak in dwarf_cus__create_cu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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. Fix the leak.

Signed-off-by: Viktor Malik <vmalik@xxxxxxxxxx>
---
 dwarf_loader.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/dwarf_loader.c b/dwarf_loader.c
index 04f5637..ad36e3c 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -3378,8 +3378,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);
 
-- 
2.46.0





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux