dfu: memory leak in dfu_free_entities()
PATCH 1/1 dfu: memory leak in dfu_free_entities()
We must free all entries that we remove from the list not just one to avoid a memory leak.
With list_for_each_entry_safe_reverse() it is safe to delete the current entry as it provides a second pointer for the next entry.
Signed-off-by Heinrich Schuchardt <[email protected]>
--- drivers/dfu/dfu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/dfu/dfu.c +1 -3
@@ -535,10 +535,8 @@ void dfu_free_entities(void)list_del (&dfu->list);if (dfu->free_entity) dfu->free_entity (dfu); - t = dfu; +free (dfu); } -if (t) -free (t);INIT_LIST_HEAD (&dfu_list); alt_num_cnt =0 ;
--
2.30.2
PATCH 1/1 dfu: memory leak in dfu_free_entities()
Quoted 5 lines · Heinrich Schuchardt
We must free all entries that we remove from the list not just one to avoid a memory leak.
With
list_for_each_entry_safe_reverse()it is safe to delete the current entry as it provides a second pointer for the next entry.
I got that wrong:
dfu_alt_init() reserves memory for dfu_alt_num entries at once. So must call free() only once.
Sorry for the noise.
Best regards
Heinrich