mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-15 03:01:09 +08:00
2e5a52414a
includes single to multiple hooks changes. ber_mem* reimplementation. namespace glue (finally naming has not be decided upon nor implemented). Added ldap_int_strdup to handle "internal" strdup'ing, this version uses hooks. ldap_pvt_strdup still available for when strdup() is missing, this version directly uses system allocators. Updated -lldif to use ber allocators. Items returned by ldif routines should be ber_memfree()d as needed.
86 lines
1.4 KiB
C
86 lines
1.4 KiB
C
/*
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
*/
|
|
#include "portable.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <ac/string.h>
|
|
|
|
#include "lber-int.h"
|
|
|
|
BerMemoryFunctions *ber_int_memory_fns = NULL;
|
|
|
|
void
|
|
ber_memfree( void *p )
|
|
{
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
assert( p != NULL );
|
|
|
|
if( ber_int_memory_fns == NULL ) {
|
|
free( p );
|
|
return;
|
|
}
|
|
|
|
assert( ber_int_memory_fns->bmf_free );
|
|
|
|
(*ber_int_memory_fns->bmf_free)( p );
|
|
}
|
|
|
|
void *
|
|
ber_memalloc( size_t s )
|
|
{
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
assert( s );
|
|
|
|
if( ber_int_memory_fns == NULL ) {
|
|
return malloc( s );
|
|
}
|
|
|
|
assert( ber_int_memory_fns->bmf_malloc );
|
|
|
|
return (*ber_int_memory_fns->bmf_malloc)( s );
|
|
}
|
|
|
|
void *
|
|
ber_memcalloc( size_t n, size_t s )
|
|
{
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
assert( n && s );
|
|
|
|
if( ber_int_memory_fns == NULL ) {
|
|
return calloc( n, s );
|
|
}
|
|
|
|
assert( ber_int_memory_fns->bmf_calloc );
|
|
|
|
return (*ber_int_memory_fns->bmf_calloc)( n, s );
|
|
}
|
|
|
|
void *
|
|
ber_memrealloc( void* p, size_t s )
|
|
{
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
if( p == NULL ) {
|
|
return ber_memalloc( s );
|
|
}
|
|
|
|
if( s == 0 ) {
|
|
ber_memfree( p );
|
|
return NULL;
|
|
}
|
|
|
|
if( ber_int_memory_fns == NULL ) {
|
|
return realloc( p, s );
|
|
}
|
|
|
|
assert( ber_int_memory_fns->bmf_realloc );
|
|
|
|
return (*ber_int_memory_fns->bmf_realloc)( p, s );
|
|
}
|
|
|