diff options
author | wtc%netscape.com <devnull@localhost> | 2002-01-24 18:11:30 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 2002-01-24 18:11:30 +0000 |
commit | 4f06d9008d215008cebccb420e43bb91de6d7d3e (patch) | |
tree | fb0ec37e552702f7360baaabad9437c2f55fb9d3 | |
parent | a57bf90ec279dd524890f69152f502f8e0ab4e68 (diff) | |
download | nspr-hg-4f06d9008d215008cebccb420e43bb91de6d7d3e.tar.gz |
Bugzilla bug 97485: fixed a few bugs in the zone allocator. Print warning
messages on memory blocks from ordinary malloc. Initialize the zone
allocator first during NSPR initialization.
Modified files: prmem.c prinit.c
-rw-r--r-- | pr/src/malloc/prmem.c | 12 | ||||
-rw-r--r-- | pr/src/misc/prinit.c | 7 |
2 files changed, 12 insertions, 7 deletions
diff --git a/pr/src/malloc/prmem.c b/pr/src/malloc/prmem.c index 0a70b439..f6d2df90 100644 --- a/pr/src/malloc/prmem.c +++ b/pr/src/malloc/prmem.c @@ -97,11 +97,12 @@ _PR_DestroyZones(void) while (mz->head) { MemBlockHdr *hdr = mz->head; mz->head = hdr->s.next; /* unlink it */ - pr_ZoneFree(hdr); + free(hdr); mz->elements--; } } } + use_zone_allocator = PR_FALSE; } void @@ -110,7 +111,7 @@ _PR_InitZones(void) int i, j; char *envp; - if (envp = getenv("NSPR_USE_ZONE_ALLOCATOR")) { + if ((envp = getenv("NSPR_USE_ZONE_ALLOCATOR")) != NULL) { use_zone_allocator = (atoi(envp) == 1); } @@ -275,6 +276,9 @@ pr_ZoneRealloc(void *oldptr, PRUint32 bytes) PR_ASSERT(mb->s.magic == ZONE_MAGIC); if (mb->s.magic != ZONE_MAGIC) { /* Maybe this just came from ordinary malloc */ + fprintf(stderr, + "Warning: reallocing memory block %p from ordinary malloc\n", + oldptr); /* We don't know how big it is. But we can fix that. */ oldptr = realloc(oldptr, bytes); if (!oldptr) { @@ -329,6 +333,8 @@ pr_ZoneFree(void *ptr) if (mb->s.magic != ZONE_MAGIC) { /* maybe this came from ordinary malloc */ + fprintf(stderr, + "Warning: freeing memory block %p from ordinary malloc\n", ptr); free(ptr); return; } @@ -342,7 +348,7 @@ pr_ZoneFree(void *ptr) if (!mz) { PR_ASSERT(blockSize > 65536); /* This block was not in any zone. Just free it. */ - free(ptr); + free(mb); return; } PR_ASSERT(mz->blockSize == blockSize); diff --git a/pr/src/misc/prinit.c b/pr/src/misc/prinit.c index cd24eeb0..e512f1e0 100644 --- a/pr/src/misc/prinit.c +++ b/pr/src/misc/prinit.c @@ -169,6 +169,9 @@ static void _PR_InitStuff(void) if (_pr_initialized) return; _pr_initialized = PR_TRUE; +#ifdef _PR_ZONE_ALLOCATOR + _PR_InitZones(); +#endif #ifdef WINNT _pr_SetNativeThreadsOnlyMode(); #endif @@ -220,10 +223,6 @@ static void _PR_InitStuff(void) _PR_InitCPUs(); #endif -#ifdef _PR_ZONE_ALLOCATOR - _PR_InitZones(); -#endif - /* * XXX: call _PR_InitMem only on those platforms for which nspr implements * malloc, for now. |