diff options
author | Anna Sztukowska <anna.sztukowska@intel.com> | 2024-08-08 17:02:38 +0200 |
---|---|---|
committer | Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | 2024-09-10 10:56:56 +0200 |
commit | da26064bfe4457d5037f3a1f1bb83a54225c6375 (patch) | |
tree | b567aa633d12c177a756145dbd850deb01353e22 /dlink.c | |
parent | imsm: save checkpoint prior to exit (diff) | |
download | mdadm-da26064bfe4457d5037f3a1f1bb83a54225c6375.tar.xz mdadm-da26064bfe4457d5037f3a1f1bb83a54225c6375.zip |
Examine.c: Fix memory leaks in Examine()
Fix memory leaks in Examine() reported by SAST analysis. Implement a
method to traverse and free all the nodes of the doubly linked list.
Replace for loop with while loop in order to improve redability of the
code and free allocated memory correctly.
Signed-off-by: Anna Sztukowska <anna.sztukowska@intel.com>
Diffstat (limited to 'dlink.c')
-rw-r--r-- | dlink.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -26,6 +26,21 @@ void dl_free(void *v) free(vv-1); } +void dl_free_all(void *head) +{ + /* The list head is linked with the list tail so in order to free + * all the elements properly there is a need to keep starting point. + */ + void *d = dl_next(head), *next; + + while (d != head) { + next = dl_next(d); + dl_free(d); + d = next; + } + dl_free(head); +} + void dl_init(void *v) { dl_next(v) = v; |