Defend against early OOM when finishing JSDHashTables (131815, r=scole, sr=jband, a=asa).

This commit is contained in:
brendan%mozilla.org 2002-03-20 02:22:50 +00:00
parent 98e56e1772
commit 94a74d7db5
2 changed files with 10 additions and 4 deletions

View File

@ -275,6 +275,7 @@ js_InitGC(JSRuntime *rt, uint32 maxbytes)
sizeof(JSGCThing));
if (!JS_DHashTableInit(&rt->gcRootsHash, JS_DHashGetStubOps(), NULL,
sizeof(JSGCRootHashEntry), GC_ROOTS_SIZE)) {
rt->gcRootsHash.ops = NULL;
return JS_FALSE;
}
rt->gcLocksHash = NULL; /* create lazily */
@ -339,8 +340,8 @@ js_FinishGC(JSRuntime *rt)
JS_FinishArenaPool(&rt->gcArenaPool);
JS_ArenaFinish();
if (rt->gcRootsHash.ops) {
#ifdef DEBUG
{
uint32 leakedroots = 0;
/* Warn (but don't assert) debug builds of any remaining roots. */
@ -360,10 +361,11 @@ js_FinishGC(JSRuntime *rt)
(unsigned long) leakedroots);
}
}
}
#endif
JS_DHashTableFinish(&rt->gcRootsHash);
JS_DHashTableFinish(&rt->gcRootsHash);
rt->gcRootsHash.ops = NULL;
}
if (rt->gcLocksHash) {
JS_DHashTableDestroy(rt->gcLocksHash);
rt->gcLocksHash = NULL;

View File

@ -1523,6 +1523,7 @@ js_InitPropertyTree(JSRuntime *rt)
{
if (!JS_DHashTableInit(&rt->propertyTreeHash, &PropertyTreeHashOps, NULL,
sizeof(JSPropertyTreeEntry), JS_DHASH_MIN_SIZE)) {
rt->propertyTreeHash.ops = NULL;
return JS_FALSE;
}
JS_InitArenaPool(&rt->propertyArenaPool, "properties",
@ -1533,6 +1534,9 @@ js_InitPropertyTree(JSRuntime *rt)
void
js_FinishPropertyTree(JSRuntime *rt)
{
JS_DHashTableFinish(&rt->propertyTreeHash);
if (rt->propertyTreeHash.ops) {
JS_DHashTableFinish(&rt->propertyTreeHash);
rt->propertyTreeHash.ops = NULL;
}
JS_FinishArenaPool(&rt->propertyArenaPool);
}