comparison mercurial/cext/revlog.c @ 38821:d814bbd22946

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
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 17 Jul 2018 23:34:55 -0700
parents 44bbc89ec5e0
children f9fc59ea3135
comparison
equal deleted inserted replaced
38820:44bbc89ec5e0 38821:d814bbd22946
1110 } 1110 }
1111 self->ntlength = 1; 1111 self->ntlength = 1;
1112 self->ntrev = (int)index_length(self) - 1; 1112 self->ntrev = (int)index_length(self) - 1;
1113 self->ntlookups = 1; 1113 self->ntlookups = 1;
1114 self->ntmisses = 0; 1114 self->ntmisses = 0;
1115 if (nt_insert(self, nullid, INT_MAX) == -1) 1115 if (nt_insert(self, nullid, INT_MAX) == -1) {
1116 free(self->nt);
1117 self->nt = NULL;
1116 return -1; 1118 return -1;
1119 }
1117 } 1120 }
1118 return 0; 1121 return 0;
1119 } 1122 }
1120 1123
1121 /* 1124 /*