Skip to contentSkip to conversation

objtool: fix potential memory leak special_get_alts()

PATCH In review Chen Wandun 2 participants 2 messages Jul 2, 2020 objtool

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 objtool: fix potential memory leak special_get_alts()

If get_alt_entry() return error, struct special_alt will leak.

Fixes 442f04c34a1a ("objtool: Add tool to perform compile-time stack metadata validation")
---
 tools/objtool/special.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/objtool/special.c +3 -1
index e893f1e48e44..90a6ba2d5895 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