ptrs_list: list_clear family accepts NULLs 56/244856/1
authorMichal Bloch <m.bloch@samsung.com>
Fri, 25 Sep 2020 06:20:13 +0000 (08:20 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 25 Sep 2020 06:20:13 +0000 (08:20 +0200)
Change-Id: Id41135a151fcc354dbe6d7556ddb2cd98eb5f581
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/shared/ptrs_list.c

index d5b9783..b8968d1 100644 (file)
@@ -121,12 +121,18 @@ void list_remove_if(list_head *head, void *user_data, cond_cb cond)
 
 void list_clear(list_head *head)
 {
+       if (!head)
+               return;
+
        while (*head)
                *head = list_remove_at(*head);
 }
 
 void list_clear_free_contents(list_head *head)
 {
+       if (!head)
+               return;
+
        while (*head) {
                free(list_at(*head));
                *head = list_remove_at(*head);
@@ -135,6 +141,9 @@ void list_clear_free_contents(list_head *head)
 
 void list_clear_custom(list_head *head, void *user_data, apply_cb clear)
 {
+       if (!head)
+               return;
+
        while (*head) {
                clear(list_at(*head), user_data);
                *head = list_remove_at(*head);