Mercurial > vim
comparison src/misc2.c @ 13244:ac42c4b11dbc v8.0.1496
patch 8.0.1496: clearing a pointer takes two lines
commit https://github.com/vim/vim/commit/d23a823669d93fb2a570a039173eefe4856ac806
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Feb 10 18:45:26 2018 +0100
patch 8.0.1496: clearing a pointer takes two lines
Problem: Clearing a pointer takes two lines.
Solution: Add VIM_CLEAR() and replace vim_clear(). (Hirohito Higashi,
closes #2629)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 10 Feb 2018 19:00:07 +0100 |
parents | fee03d646e42 |
children | 69517d67421f |
comparison
equal
deleted
inserted
replaced
13243:899b19739188 | 13244:ac42c4b11dbc |
---|---|
1825 | 1825 |
1826 /* | 1826 /* |
1827 * Replacement for free() that ignores NULL pointers. | 1827 * Replacement for free() that ignores NULL pointers. |
1828 * Also skip free() when exiting for sure, this helps when we caught a deadly | 1828 * Also skip free() when exiting for sure, this helps when we caught a deadly |
1829 * signal that was caused by a crash in free(). | 1829 * signal that was caused by a crash in free(). |
1830 * If you want to set NULL after calling this function, you should use | |
1831 * VIM_CLEAR() instead. | |
1830 */ | 1832 */ |
1831 void | 1833 void |
1832 vim_free(void *x) | 1834 vim_free(void *x) |
1833 { | 1835 { |
1834 if (x != NULL && !really_exiting) | 1836 if (x != NULL && !really_exiting) |
1835 { | 1837 { |
1836 #ifdef MEM_PROFILE | 1838 #ifdef MEM_PROFILE |
1837 mem_pre_free(&x); | 1839 mem_pre_free(&x); |
1838 #endif | 1840 #endif |
1839 free(x); | 1841 free(x); |
1840 } | |
1841 } | |
1842 | |
1843 /* | |
1844 * Like vim_free(), and also set the pointer to NULL. | |
1845 */ | |
1846 void | |
1847 vim_clear(void **x) | |
1848 { | |
1849 if (*x != NULL) | |
1850 { | |
1851 vim_free(*x); | |
1852 *x = NULL; | |
1853 } | 1842 } |
1854 } | 1843 } |
1855 | 1844 |
1856 #ifndef HAVE_MEMSET | 1845 #ifndef HAVE_MEMSET |
1857 void * | 1846 void * |