summaryrefslogtreecommitdiffstats
path: root/dlink.c
diff options
context:
space:
mode:
authorAnna Sztukowska <anna.sztukowska@intel.com>2024-08-08 17:02:38 +0200
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-09-10 10:56:56 +0200
commitda26064bfe4457d5037f3a1f1bb83a54225c6375 (patch)
treeb567aa633d12c177a756145dbd850deb01353e22 /dlink.c
parentimsm: save checkpoint prior to exit (diff)
downloadmdadm-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.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/dlink.c b/dlink.c
index 69aa7aa3..34633672 100644
--- a/dlink.c
+++ b/dlink.c
@@ -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;