diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c --- a/contrib/chg/chg.c +++ b/contrib/chg/chg.c @@ -220,7 +220,10 @@ static void execcmdserver(const struct c const char **argv = mallocx(sizeof(char *) * argsize); memcpy(argv, baseargv, sizeof(baseargv)); - memcpy(argv + baseargvsize, opts->args, sizeof(char *) * opts->argsize); + if (opts->args) { + size_t size = sizeof(char *) * opts->argsize; + memcpy(argv + baseargvsize, opts->args, size); + } argv[argsize - 1] = NULL; if (putenv("CHGINTERNALMARK=") != 0) 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 @@ -185,15 +185,13 @@ static void lazymanifest_dealloc(lazyman { /* free any extra lines we had to allocate */ int i; - for (i = 0; i < self->numlines; i++) { + for (i = 0; self->lines && (i < self->numlines); i++) { if (self->lines[i].from_malloc) { 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 @@ -333,10 +333,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); }