]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/sl_malloc.c
Do not require ac/string.h for lber_pvt.h
[openldap] / servers / slapd / sl_malloc.c
index 3feb7739030a64c2bac5337239b56836c20ff89b..d7c60be6736f2fbce7bbceef6b1d03d99025ee32 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2014 The OpenLDAP Foundation.
+ * Copyright 2003-2018 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -137,6 +137,9 @@ slap_sl_mem_destroy(
        struct slab_object *so;
        int i;
 
+       if (!sh)
+               return;
+
        if (!sh->sh_stack) {
                for (i = 0; i <= sh->sh_maxorder - order_start; i++) {
                        so = LDAP_LIST_FIRST(&sh->sh_free[i]);
@@ -279,16 +282,17 @@ slap_sl_mem_create(
 }
 
 /*
- * Separate memory context from thread context.  Future users must
+ * Assign memory context to thread context. Use NULL to detach
+ * current memory context from thread. Future users must
  * know the context, since ch_free/slap_sl_context() cannot find it.
  */
 void
-slap_sl_mem_detach(
+slap_sl_mem_setctx(
        void *thrctx,
        void *memctx
 )
 {
-       SET_MEMCTX(thrctx, NULL, 0);
+       SET_MEMCTX(thrctx, memctx, slap_sl_mem_destroy);
 }
 
 void *
@@ -648,6 +652,21 @@ slap_sl_free(void *ptr, void *ctx)
        }
 }
 
+void
+slap_sl_release( void *ptr, void *ctx )
+{
+       struct slab_heap *sh = ctx;
+       if ( sh && ptr >= sh->sh_base && ptr <= sh->sh_end )
+               sh->sh_last = ptr;
+}
+
+void *
+slap_sl_mark( void *ctx )
+{
+       struct slab_heap *sh = ctx;
+       return sh->sh_last;
+}
+
 /*
  * Return the memory context of the current thread if the given block of
  * memory belongs to it, otherwise return NULL.