# HG changeset patch # User Martin von Zweigbergk # Date 2018-07-18 06:34:55 # Node ID d814bbd229467f7e5d866fd3af41df8beb131b9a # Parent 44bbc89ec5e0f4735d9ccf2f3299ad2eca0d3732 revlog: remove side effect from failed nt_init() If nt_init() successfully allocates memory for the node tree but then runs out of memory while trying to insert nullid into it, it will leave the node tree pointer set on the index object. That means that future node tree operations will think that the tree is properly initialized. It seems very unlikely to make a difference in practice (if nt_init() runs out of memory, not much else will probably work), but since I spotted it, I figured I might as well fix it. Differential Revision: https://phab.mercurial-scm.org/D4028 diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c +++ b/mercurial/cext/revlog.c @@ -1112,8 +1112,11 @@ static int nt_init(indexObject *self) self->ntrev = (int)index_length(self) - 1; self->ntlookups = 1; self->ntmisses = 0; - if (nt_insert(self, nullid, INT_MAX) == -1) + if (nt_insert(self, nullid, INT_MAX) == -1) { + free(self->nt); + self->nt = NULL; return -1; + } } return 0; }