diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-11 12:42:52 -0300 |
---|---|---|
committer | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-11 20:22:36 -0300 |
commit | 8ee5659d83383d857039f8fc58d7ebc21df27905 (patch) | |
tree | 548d178953fe620fd2edda4e746a0186ad222aed /src | |
parent | b603404487e0daa101deacbe346aa2fc9ee255c7 (diff) | |
download | rneovim-8ee5659d83383d857039f8fc58d7ebc21df27905.tar.gz rneovim-8ee5659d83383d857039f8fc58d7ebc21df27905.tar.bz2 rneovim-8ee5659d83383d857039f8fc58d7ebc21df27905.zip |
GA_DEEP_FREE_PTR: deep free macro for garrays that store simple pointers
By "simple pointer" I mean a pointer that can be freed with a call to `free`
without leaking any member pointer.
This macro does exactly what `ga_clear_strings` does.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_cmds.c | 4 | ||||
-rw-r--r-- | src/nvim/garray.c | 5 | ||||
-rw-r--r-- | src/nvim/garray.h | 8 | ||||
-rw-r--r-- | src/nvim/spell.c | 8 |
4 files changed, 11 insertions, 14 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 5ae03c6be3..701e969393 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -5625,9 +5625,7 @@ helptags_one ( if (mix) got_int = FALSE; /* continue with other languages */ - for (int i = 0; i < ga.ga_len; ++i) - free(((char_u **)ga.ga_data)[i]); - ga_clear(&ga); + GA_DEEP_CLEAR_PTR(&ga); fclose(fd_tags); /* there is no check for an error... */ } diff --git a/src/nvim/garray.c b/src/nvim/garray.c index 08a38493bf..c4f8f66bfe 100644 --- a/src/nvim/garray.c +++ b/src/nvim/garray.c @@ -37,10 +37,7 @@ void ga_clear(garray_T *gap) /// @param gap void ga_clear_strings(garray_T *gap) { - for (int i = 0; i < gap->ga_len; ++i) { - free(((char_u **)(gap->ga_data))[i]); - } - ga_clear(gap); + GA_DEEP_CLEAR_PTR(gap); } /// Initialize a growing array. diff --git a/src/nvim/garray.h b/src/nvim/garray.h index 52493d6391..b758fce5da 100644 --- a/src/nvim/garray.h +++ b/src/nvim/garray.h @@ -61,4 +61,12 @@ static inline void *ga_append_via_ptr(garray_T *gap, size_t item_size) ga_clear(_gap); \ } while (false) +#define FREE_PTR_PTR(ptr) free(*(ptr)) + +/// Call `free` for every pointer stored in the garray and then frees the +/// garray. +/// +/// @param gap the garray to be freed +#define GA_DEEP_CLEAR_PTR(gap) GA_DEEP_CLEAR(gap, void*, FREE_PTR_PTR) + #endif // NVIM_GARRAY_H diff --git a/src/nvim/spell.c b/src/nvim/spell.c index fbdd58f4d3..8853b39fc2 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2420,13 +2420,7 @@ static void slang_clear(slang_T *lp) gap = &lp->sl_sal; if (lp->sl_sofo) { // "ga_len" is set to 1 without adding an item for latin1 - if (gap->ga_data != NULL) { - // SOFOFROM and SOFOTO items: free lists of wide characters. - for (int i = 0; i < gap->ga_len; ++i) { - free(((int **)gap->ga_data)[i]); - } - } - ga_clear(gap); + GA_DEEP_CLEAR_PTR(gap); } else { // SAL items: free salitem_T items GA_DEEP_CLEAR(gap, salitem_T, free_salitem); |