# HG changeset patch # User Josef 'Jeff' Sipek # Date 2018-06-13 14:37:39 # Node ID d9e87566f879697b9ea8c8defbb5871a62f0e49f # Parent 6cc5d01a58a6485aa6b43f356f852f65e54d2a2d cext: stop worrying and love the free(NULL) There is no need to check for a NULL pointer before calling free since free(NULL) is defined by C standards as a no-op. Lots of software relies on this behavior so it is completely safe to call even on the most obscure of systems. diff --git a/mercurial/cext/bdiff.c b/mercurial/cext/bdiff.c --- a/mercurial/cext/bdiff.c +++ b/mercurial/cext/bdiff.c @@ -155,12 +155,8 @@ cleanup: PyEval_RestoreThread(_save); PyBuffer_Release(&ba); PyBuffer_Release(&bb); - if (al) { - free(al); - } - if (bl) { - free(bl); - } + free(al); + free(bl); if (l.next) { bdiff_freehunks(l.next); } diff --git a/mercurial/cext/manifest.c b/mercurial/cext/manifest.c --- a/mercurial/cext/manifest.c +++ b/mercurial/cext/manifest.c @@ -190,10 +190,8 @@ static void lazymanifest_dealloc(lazyman free(self->lines[i].start); } } - if (self->lines) { - free(self->lines); - self->lines = NULL; - } + free(self->lines); + self->lines = NULL; if (self->pydata) { Py_DECREF(self->pydata); self->pydata = NULL; diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c +++ b/mercurial/cext/revlog.c @@ -319,10 +319,8 @@ static void _index_clearcaches(indexObje PyMem_Free(self->offsets); self->offsets = NULL; } - if (self->nt) { - free(self->nt); - self->nt = NULL; - } + free(self->nt); + self->nt = NULL; Py_CLEAR(self->headrevs); }