Skip to contentSkip to conversation

compile-i386.c: fix a memory leak in sort_array()

PATCH Applied Martin Kepplinger 2 participants 2 messages Sep 10, 2017 – Sep 12, 2017 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compile-i386.c: fix a memory leak in sort_array()

sort_array() locally allocates a list it. Let's free it before returning in order to avoid memory to leak.

---
 compile-i386.c | 1 +
 1 file changed, 1 insertion(+)
compile-i386.c +1 -0
index 44b72ec..e4d3f27 100644
@@ -1048,6 +1048,7 @@ static void sort_array(struct expression *expr)
 			*THIS_ADDRESS(entry) = list[i++];
 	} END_FOR_EACH_PTR(entry);
 
+	free(list);
 }
 
 static void emit_array(struct symbol *sym)
Signature · 1 line
2.11.0
maintainer Applied
#1 lore raw
Quoted 4 lines · Martin Kepplinger

sort_array() locally allocates a list it. Let's free it before returning in order to avoid memory to leak.

Applied. While I am reading the code in that function, I notice there is expression_list_size() which can get the size of the expression list.

There is also a sort_list() in sort.c which can simplify sort_array().

Chris