diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-10-17 07:55:21 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-10-17 07:55:21 +0200 |
commit | 972bd26e5e2e2e2303ccff457ae0493e2f45a284 (patch) | |
tree | dba353e59e224b8e3663827f3c4e66130c4027fc /src | |
parent | 413f60ff309da5643af73f59932e6deb763f6261 (diff) | |
download | weechat-972bd26e5e2e2e2303ccff457ae0493e2f45a284.zip |
core: call "callback_free" in functions arraylist_{remove|clear|free}
This fixes a memory leak in completions which are using this callback
to free words in the completion list.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-arraylist.c | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/core/wee-arraylist.c b/src/core/wee-arraylist.c index 1f1710d8f..3d2ab4bab 100644 --- a/src/core/wee-arraylist.c +++ b/src/core/wee-arraylist.c @@ -479,12 +479,6 @@ arraylist_insert (struct t_arraylist *arraylist, int index, void *pointer) arraylist, arraylist->data[index], pointer)) == 0)) { - if (arraylist->callback_free) - { - (arraylist->callback_free) (arraylist->callback_free_data, - arraylist, - arraylist->data[index]); - } arraylist_remove (arraylist, index); } } @@ -504,12 +498,6 @@ arraylist_insert (struct t_arraylist *arraylist, int index, void *pointer) arraylist, arraylist->data[i], pointer) == 0) { - if (arraylist->callback_free) - { - (arraylist->callback_free) (arraylist->callback_free_data, - arraylist, - arraylist->data[i]); - } arraylist_remove (arraylist, i); } else @@ -568,6 +556,13 @@ arraylist_remove (struct t_arraylist *arraylist, int index) if (!arraylist || (index < 0) || (index >= arraylist->size)) return -1; + if (arraylist->callback_free) + { + (arraylist->callback_free) (arraylist->callback_free_data, + arraylist, + arraylist->data[index]); + } + if (index < arraylist->size - 1) { memmove (&arraylist->data[index], @@ -599,9 +594,21 @@ arraylist_remove (struct t_arraylist *arraylist, int index) int arraylist_clear (struct t_arraylist *arraylist) { + int i; + if (!arraylist) return 0; + if (arraylist->callback_free) + { + for (i = 0; i < arraylist->size; i++) + { + (arraylist->callback_free) (arraylist->callback_free_data, + arraylist, + arraylist->data[i]); + } + } + if (arraylist->data && (arraylist->size_alloc != arraylist->size_alloc_min)) { @@ -617,6 +624,12 @@ arraylist_clear (struct t_arraylist *arraylist) arraylist->size_alloc = arraylist->size_alloc_min; } } + else if (arraylist->size_alloc > 0) + { + memset (arraylist->data, + 0, + arraylist->size_alloc * sizeof (*arraylist->data)); + } arraylist->size = 0; @@ -630,9 +643,21 @@ arraylist_clear (struct t_arraylist *arraylist) void arraylist_free (struct t_arraylist *arraylist) { + int i; + if (!arraylist) return; + if (arraylist->callback_free) + { + for (i = 0; i < arraylist->size; i++) + { + (arraylist->callback_free) (arraylist->callback_free_data, + arraylist, + arraylist->data[i]); + } + } + if (arraylist->data) free (arraylist->data); |