From 30294ea4495e48e0103fee4d855737a281cc49fa Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 25 Nov 2007 21:08:01 +0000 Subject: * nscd/nscd.h (MAX_STACK_USE): Define. * nscd/mem.c (MAX_STACK_USE): Remove definition here. (gc): Initialize stack_used based on allocation in prune_cache. * nscd/cache.c (prune_cache): Use heap for mark array if necessary. Clear array bfore use. * nscd/aicache.c (addhstaiX): Update statistics counter in case memory allocate failed. --- nscd/mem.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'nscd/mem.c') diff --git a/nscd/mem.c b/nscd/mem.c index 5c269219b3..048e3ddd32 100644 --- a/nscd/mem.c +++ b/nscd/mem.c @@ -74,10 +74,6 @@ sort_he_data (const void *p1, const void *p2) #define ALLBITS ((((BITMAP_T) 1) << BITS) - 1) #define HIGHBIT (((BITMAP_T) 1) << (BITS - 1)) -/* Maximum size of stack frames we allow the thread to use. We use - 80% of the thread stack size. */ -#define MAX_STACK_USE ((8 * NSCD_THREAD_STACKSIZE) / 10) - static void markrange (BITMAP_T *mark, ref_t start, size_t len) @@ -129,7 +125,11 @@ gc (struct database_dyn *db) BITMAP_T *mark; bool mark_use_malloc; - size_t stack_used = 0; + /* In prune_cache we are also using a dynamically allocated array. + If the array in the caller is too large we have malloc'ed it. */ + size_t stack_used = sizeof (bool) * db->head->module; + if (__builtin_expect (stack_used > MAX_STACK_USE, 0)) + stack_used = 0; size_t memory_needed = ((db->head->first_free / BLOCK_ALIGN + BITS - 1) / BITS) * sizeof (BITMAP_T); if (memory_needed <= MAX_STACK_USE) -- cgit v1.2.1