X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fsl_malloc.c;h=79317158174d4e5ccdccc9c6049ad9d514564376;hb=c2a9642850cef813e15f6d8e29799e2b99e52726;hp=b7a40644301287c112907c146707c57fa2bb1c20;hpb=b70d375964c55214bd3039c80acfc4f3c0d682f1;p=openldap diff --git a/servers/slapd/sl_malloc.c b/servers/slapd/sl_malloc.c index b7a4064430..7931715817 100644 --- a/servers/slapd/sl_malloc.c +++ b/servers/slapd/sl_malloc.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2003-2004 The OpenLDAP Foundation. + * Copyright 2003-2005 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -207,9 +207,13 @@ slap_sl_mem_create( sh->sh_map = (unsigned char **) ch_malloc(order * sizeof(unsigned char *)); for (i = 0; i < order; i++) { - sh->sh_map[i] = (unsigned char *) - ch_malloc(size >> (1 << (order_start + i + 3))); - memset(sh->sh_map[i], 0, size >> (1 << (order_start + i + 3))); + int shiftamt = order_start + 1 + i; + int nummaps = size >> shiftamt; + assert(nummaps); + nummaps >>= 3; + if (!nummaps) nummaps = 1; + sh->sh_map[i] = (unsigned char *) ch_malloc(nummaps); + memset(sh->sh_map[i], 0, nummaps); } sh->sh_stack = stack; return sh; @@ -248,8 +252,6 @@ slap_sl_malloc( /* ber_set_option calls us like this */ if (!ctx) return ber_memalloc_x(size, NULL); - Debug(LDAP_DEBUG_TRACE, "==> slap_sl_malloc (%d)\n", size, 0, 0); - /* round up to doubleword boundary */ size += sizeof(ber_len_t) + pad; size &= ~pad; @@ -298,7 +300,7 @@ slap_sl_malloc( } so_right = LDAP_LIST_FIRST(&sh->sh_sopool); LDAP_LIST_REMOVE(so_right, so_link); - so_right->so_ptr = so_left->so_ptr + (1 << j); + so_right->so_ptr = (void *)((char *)so_left->so_ptr + (1 << j)); if (j == order + 1) { ptr = so_left->so_ptr; diff = (unsigned long)((char*)ptr - @@ -324,6 +326,9 @@ slap_sl_malloc( return (void*)ch_malloc(size); } } + + /* FIXME: missing return; guessing... */ + return NULL; } void * @@ -413,8 +418,6 @@ slap_sl_free(void *ptr, void *ctx) unsigned long diff; int i, k, inserted = 0; - Debug( LDAP_DEBUG_TRACE, "==> slap_sl_free \n", 0, 0, 0); - if (!sh || ptr < sh->sh_base || ptr >= sh->sh_end) { ber_memfree_x(ptr, NULL); } else if (sh->sh_stack && (char *)ptr + p[-1] == sh->sh_last) { @@ -495,7 +498,7 @@ slap_sl_free(void *ptr, void *ctx) while (so) { if ((char*)so->so_ptr == (char*)tmpp) { LDAP_LIST_REMOVE(so, so_link); - } else if ((char*)tmpp == so->so_ptr + order_size) { + } else if ((char*)tmpp == (char *)so->so_ptr + order_size) { LDAP_LIST_REMOVE(so, so_link); tmpp = so->so_ptr; break; @@ -549,6 +552,8 @@ slap_sl_context( void *ptr ) struct slab_heap *sh = NULL; void *ctx; + if ( slapMode & SLAP_TOOL_MODE ) return NULL; + #ifdef NO_THREADS sh = slheap; #else