From 25f5c3ba98f12a0bfabfe7aaeb2d692affb83fc8 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Wed, 2 Jul 1997 19:33:23 +0000 Subject: [PATCH] Have another go at the malloc-sysv initialization. PR: 4002 Pointed out by: bde --- lib/libc/stdlib/malloc.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index acd7e3549c95..88bd04bccf5e 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id: malloc.c,v 1.26 1997/06/22 17:54:27 phk Exp $ + * $Id: malloc.c,v 1.27 1997/07/01 18:39:38 phk Exp $ * */ @@ -458,9 +458,6 @@ malloc_init () malloc_ninfo = malloc_pagesize / sizeof *page_dir; - /* Been here, done that */ - malloc_started++; - /* Recalculate the cache size in bytes, and make sure it's nonzero */ if (!malloc_cache) @@ -474,6 +471,8 @@ malloc_init () */ px = (struct pgfree *) imalloc (sizeof *px); + /* Been here, done that */ + malloc_started++; } /* @@ -696,9 +695,6 @@ imalloc(size_t size) { void *result; - if (!malloc_started) - malloc_init(); - if (suicide) abort(); @@ -732,11 +728,6 @@ irealloc(void *ptr, size_t size) if (suicide) abort(); - if (!malloc_started) { - wrtwarning("malloc() has never been called.\n"); - return 0; - } - index = ptr2index(ptr); if (index < malloc_pageshift) { @@ -1068,6 +1059,8 @@ malloc(size_t size) malloc_active--; return (0); } + if (!malloc_started) + malloc_init(); if (malloc_sysv && !size) r = 0; else @@ -1109,6 +1102,12 @@ realloc(void *ptr, size_t size) malloc_active--; return (0); } + if (ptr && !malloc_started) { + wrtwarning("malloc() has never been called.\n"); + ptr = 0; + } + if (!malloc_started) + malloc_init(); if (malloc_sysv && !size) { ifree(ptr); r = 0;