* mailbox/list.c (list_destroy) : Call to list->destroy_item() when
the data is free(). (list_set_destroy_item): New function.
Showing
1 changed file
with
10 additions
and
0 deletions
... | @@ -62,6 +62,8 @@ list_destroy (list_t *plist) | ... | @@ -62,6 +62,8 @@ list_destroy (list_t *plist) |
62 | { | 62 | { |
63 | previous = current; | 63 | previous = current; |
64 | current = current->next; | 64 | current = current->next; |
65 | if (list->destroy_item) | ||
66 | list->destroy_item (previous->item); | ||
65 | free (previous); | 67 | free (previous); |
66 | } | 68 | } |
67 | monitor_unlock (list->monitor); | 69 | monitor_unlock (list->monitor); |
... | @@ -293,3 +295,11 @@ list_do (list_t list, list_action_t * action, void *cbdata) | ... | @@ -293,3 +295,11 @@ list_do (list_t list, list_action_t * action, void *cbdata) |
293 | monitor_unlock (list->monitor); | 295 | monitor_unlock (list->monitor); |
294 | return status; | 296 | return status; |
295 | } | 297 | } |
298 | |||
299 | int | ||
300 | list_set_destroy_item (list_t list, void (*destroy_item)(void *item)) | ||
301 | { | ||
302 | if (list == NULL) | ||
303 | return EINVAL; | ||
304 | list->destroy_item = destroy_item; | ||
305 | } | ... | ... |
-
Please register or sign in to post a comment