mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
This commit is contained in:
parent
b603404487
commit
8ee5659d83
@ -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... */
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user