Skip to contentSkip to conversation

fix memory leak in special_get_alts

PATCH In review Gaurav Singh 2 participants 2 messages Jun 22, 2020 objtool

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix memory leak in special_get_alts

Free alt before returning to avoid memory leak.

---
 tools/objtool/special.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/objtool/special.c +3 -1
index e74e0189de22..f6f7dee1ba77 100644
@@ -188,8 +188,10 @@ int special_get_alts(struct elf *elf, struct list_head *alts)
 			memset(alt, 0, sizeof(*alt));
 
 			ret = get_alt_entry(elf, entry, sec, idx, alt);
-			if (ret)
+			if (ret) {
+				free(alt);
 				return ret;
+			}
 
 			list_add_tail(&alt->list, alts);
 		}
Signature · 1 line
2.17.1
#1 lore raw
Quoted 3 lines · Gaurav Singh

Free alt before returning to avoid memory leak.

Hi Gaurav,

Since objtool is a short-lived (and performance sensitive) process, we don't care about memory leaks. In fact we intentionally don't fix them.

Signature · 1 line
Josh