myrealloc is pointer to a realloc() wrapper.
Must be first library call or else.
#define LBER_OPT_BER_DEBUG 0x02
#define LBER_OPT_DEBUG_LEVEL LBER_OPT_BER_DEBUG
+
#define LBER_OPT_LOG_PRINT_FN 0x8001
+#define LBER_OPT_MEMORY_FN 0x8002
typedef void (*BER_LOG_PRINT_FN) LDAP_P(( char *buf ));
+typedef void* (*BER_MEMORY_FN) LDAP_P(( void *p, size_t size ));
/* LBER Sockbuf options */
#define LBER_TO_FILE 0x01 /* to a file referenced by sb_fd */
{
assert(bv != NULL); /* bv damn better point to something */
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
if ( bv->bv_val != NULL )
LBER_FREE( bv->bv_val );
LBER_FREE( (char *) bv );
assert(bv != NULL); /* bv damn better point to something */
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
for ( i = 0; bv[i] != NULL; i++ )
ber_bvfree( bv[i] );
LBER_FREE( (char *) bv );
assert( bv != NULL );
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
if( bv == NULL ) {
return NULL;
}
{
BerElement *ber;
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
ber = (BerElement *) LBER_CALLOC( 1, sizeof(BerElement) );
if ( ber == NULLBER )
{
assert( ber != NULL );
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
(void) memset( (char *)ber, '\0', sizeof( BerElement ));
ber->ber_valid = LBER_VALID_BERELEMENT;
ber->ber_tag = LBER_DEFAULT;
assert( bv != NULL );
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
if ( bv == NULL ) {
return NULL;
}
assert( bvPtr != NULL );
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
if(bvPtr == NULL) {
return( -1 );
}
LDAP_BEGIN_DECL
+extern BER_MEMORY_FN ber_int_realloc;
+
struct lber_options {
short lbo_valid;
#define LBER_UNINITIALIZED 0x0
int loglvl,
const Seqorset *sos ));
+
/* memory.c */
/* simple macros to realloc for now */
-#define LBER_MALLOC(s) (realloc(NULL,(s)))
-#define LBER_CALLOC(n,s) (calloc((n),(s)))
-#define LBER_REALLOC(p,s) (realloc((p),(s)))
-#define LBER_FREE(p) (realloc((p),(size_t)0))
+#define LBER_MALLOC(s) \
+ (ber_int_realloc \
+ ? (*ber_int_realloc)(NULL,(s)) \
+ : realloc(NULL,(s)))
+
+#define LBER_CALLOC(n,s) \
+ (ber_int_realloc \
+ ? ber_int_calloc((n),(s)) \
+ : calloc((n),(s)))
+
+#define LBER_REALLOC(p,s) \
+ (ber_int_realloc \
+ ? (*ber_int_realloc)((p),(s)) \
+ : realloc((p),(s)))
+
+#define LBER_FREE(p) \
+ (ber_int_realloc \
+ ? (*ber_int_realloc)((p),(size_t)0) \
+ : realloc((p),(size_t)0))
+
+LDAP_F( void * )
+ber_int_calloc LDAP_P((
+ size_t n,
+ size_t size ));
+
/* sockbuf.c */
void
ber_memfree( void *p )
{
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
LBER_FREE( p );
}
void *
ber_memalloc( size_t s )
{
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
return LBER_MALLOC( s );
}
void *
ber_memcalloc( size_t n, size_t s )
{
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
return LBER_CALLOC( n, s );
}
void *
ber_memrealloc( void* p, size_t s )
{
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
return LBER_REALLOC( p, s );
}
+BER_MEMORY_FN ber_int_realloc = NULL;
+
+void *
+ber_int_calloc( size_t n, size_t s )
+{
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
+ {
+ size_t size = n * s;
+ void *p = (*ber_int_realloc)( NULL, size );
+ return p ? memset( p, 0, size ) : p;
+ }
+}
+
BerElement *ber;
Sockbuf *sb;
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
if(outvalue == NULL) {
/* no place to get to */
return LBER_OPT_ERROR;
BerElement *ber;
Sockbuf *sb;
+ if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
+ && ( option == LBER_OPT_MEMORY_FN )
+ && ( invalue != NULL ))
+ {
+ ber_int_realloc = (BER_MEMORY_FN) invalue;
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+ return LBER_OPT_SUCCESS;
+ }
+
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
if(invalue == NULL) {
/* no place to set from */
return LBER_OPT_ERROR;
Sockbuf *ber_sockbuf_alloc( void )
{
- Sockbuf *sb = LBER_CALLOC(1, sizeof(Sockbuf));
+ Sockbuf *sb;
+
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
+ sb = LBER_CALLOC(1, sizeof(Sockbuf));
if( sb == NULL ) return NULL;
{
assert( sb != NULL);
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
sb->sb_valid=LBER_VALID_SOCKBUF;
sb->sb_options = 0;
sb->sb_debug = 0;