static int not, verbose, contoper;
static LDAP *ld;
-#define safe_realloc( ptr, size ) ( (ptr) == NULL ? malloc( size ) : \
- realloc( ptr, size ))
-
static int dodelete LDAP_P((
LDAP *ld,
char *dn));
static int new, replace, not, verbose, contoper, force, valsfromfiles;
static LDAP *ld;
-#define safe_realloc( ptr, size ) ( (ptr) == NULL ? malloc( size ) : \
- realloc( ptr, size ))
-
#define LDAPMOD_MAXLINE 4096
/* strings found in replog/LDIF entries (mostly lifted from slurpd/slurp.h) */
}
if ( pmods == NULL || pmods[ i ] == NULL ) {
- if (( pmods = (LDAPMod **)safe_realloc( pmods, (i + 2) *
+ if (( pmods = (LDAPMod **)realloc( pmods, (i + 2) *
sizeof( LDAPMod * ))) == NULL ) {
- perror( "safe_realloc" );
+ perror( "realloc" );
exit( 1 );
}
*pmodsp = pmods;
}
}
if (( pmods[ i ]->mod_bvalues =
- (struct berval **)safe_realloc( pmods[ i ]->mod_bvalues,
+ (struct berval **)ber_memrealloc( pmods[ i ]->mod_bvalues,
(j + 2) * sizeof( struct berval * ))) == NULL ) {
- perror( "safe_realloc" );
+ perror( "ber_realloc" );
exit( 1 );
}
pmods[ i ]->mod_bvalues[ j + 1 ] = NULL;
- if (( bvp = (struct berval *)malloc( sizeof( struct berval )))
+ if (( bvp = (struct berval *)ber_memalloc( sizeof( struct berval )))
== NULL ) {
- perror( "malloc" );
+ perror( "ber_memalloc" );
exit( 1 );
}
pmods[ i ]->mod_bvalues[ j ] = bvp;
-/*
- * for Windows we need local versions of the berval
- * free functions because the LDAP DLL uses a different
- * heap.
- */
-
-static void
-l_ber_bvfree( struct berval *bv )
-{
- if ( bv != NULL ) {
- if ( bv->bv_val != NULL ) {
- free( bv->bv_val );
- }
- free( (char *) bv );
- }
-}
-
-static void
-l_ber_bvecfree( struct berval **bv )
-{
- int i;
-
- for ( i = 0; bv[i] != NULL; i++ ) {
- l_ber_bvfree( bv[i] );
- }
- free( (char *) bv );
-}
-
static void
freepmods( LDAPMod **pmods )
{
for ( i = 0; pmods[ i ] != NULL; ++i ) {
if ( pmods[ i ]->mod_bvalues != NULL ) {
- l_ber_bvecfree( pmods[ i ]->mod_bvalues );
+ ber_bvecfree( pmods[ i ]->mod_bvalues );
}
if ( pmods[ i ]->mod_type != NULL ) {
free( pmods[ i ]->mod_type );
if ( lcur + len + 1 > lmax ) {
lmax = LDAPMOD_MAXLINE
* (( lcur + len + 1 ) / LDAPMOD_MAXLINE + 1 );
- if (( buf = (char *)safe_realloc( buf, lmax )) == NULL ) {
- perror( "safe_realloc" );
+ if (( buf = (char *)realloc( buf, lmax )) == NULL ) {
+ perror( "realloc" );
exit( 1 );
}
}
static int not, verbose, contoper;
static LDAP *ld;
-#define safe_realloc( ptr, size ) ( (ptr) == NULL ? malloc( size ) : \
- realloc( ptr, size ))
-
static int domodrdn LDAP_P((
LDAP *ld,
char *dn,
ber_sockbuf_free(
Sockbuf *sb );
+/*
+ * LBER memory.c
+ */
+LDAP_F( void * )
+ber_memalloc LDAP_P((
+ size_t s ));
+
+LDAP_F( void * )
+ber_memrealloc LDAP_P((
+ void* p,
+ size_t s ));
+
+LDAP_F( void * )
+ber_memcalloc LDAP_P((
+ size_t n,
+ size_t s ));
+
+LDAP_F( void )
+ber_memfree LDAP_P((
+ void* p ));
LDAP_END_DECL
* in free.c
*/
+LDAP_F( void * )
+ldap_memalloc LDAP_P((
+ size_t s ));
+
+LDAP_F( void * )
+ldap_memrealloc LDAP_P((
+ void* p,
+ size_t s ));
+
+LDAP_F( void * )
+ldap_memcalloc LDAP_P((
+ size_t n,
+ size_t s ));
+
LDAP_F( void )
ldap_memfree LDAP_P((
- void *p ));
+ void* p ));
LDAP_F( void )
ldap_getfilter_free LDAP_P((
return( LBER_DEFAULT );
}
if ( datalen > *len ) {
- free( transbuf );
+ LBER_FREE( transbuf );
return( LBER_DEFAULT );
}
SAFEMEMCPY( buf, transbuf, datalen );
- free( transbuf );
+ LBER_FREE( transbuf );
--datalen;
}
#endif /* STR_TRANSLATION */
return( LBER_DEFAULT );
}
- if ( (*buf = (char *) malloc( (size_t)datalen + 1 )) == NULL )
+ if ( (*buf = (char *) LBER_MALLOC( (size_t)datalen + 1 )) == NULL )
return( LBER_DEFAULT );
if ( (unsigned long) ber_read( ber, *buf, datalen ) != datalen ) {
- free( *buf );
+ LBER_FREE( *buf );
*buf = NULL;
return( LBER_DEFAULT );
}
++datalen;
if ( (*(ber->ber_decode_translate_proc))( buf, &datalen, 1 )
!= 0 ) {
- free( *buf );
+ LBER_FREE( *buf );
*buf = NULL;
return( LBER_DEFAULT );
}
return( LBER_DEFAULT );
}
- if ( (*bv = (struct berval *) malloc( sizeof(struct berval) )) == NULL )
+ if ( (*bv = (struct berval *) LBER_MALLOC( sizeof(struct berval) )) == NULL )
return( LBER_DEFAULT );
- if ( ((*bv)->bv_val = (char *) malloc( (size_t)len + 1 )) == NULL ) {
- free( *bv );
+ if ( ((*bv)->bv_val = (char *) LBER_MALLOC( (size_t)len + 1 )) == NULL ) {
+ LBER_FREE( *bv );
*bv = NULL;
return( LBER_DEFAULT );
}
}
--datalen;
- if ( (*buf = (char *) malloc( (size_t)datalen )) == NULL )
+ if ( (*buf = (char *) LBER_MALLOC( (size_t)datalen )) == NULL )
return( LBER_DEFAULT );
if ( ber_read( ber, (char *)&unusedbits, 1 ) != 1 ) {
- free( buf );
+ LBER_FREE( buf );
*buf = NULL;
return( LBER_DEFAULT );
}
if ( (unsigned long) ber_read( ber, *buf, datalen ) != datalen ) {
- free( buf );
+ LBER_FREE( buf );
*buf = NULL;
return( LBER_DEFAULT );
}
tag != LBER_DEFAULT && rc != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
{
- if ( *sss == NULL ) {
- *sss = (char **) malloc(
- 2 * sizeof(char *) );
- } else {
- *sss = (char **) realloc( *sss,
- (j + 2) * sizeof(char *) );
- }
+ *sss = (char **) LBER_REALLOC( *sss,
+ (j + 2) * sizeof(char *) );
+
rc = ber_get_stringa( ber, &((*sss)[j]) );
j++;
}
tag != LBER_DEFAULT && rc != LBER_DEFAULT;
tag = ber_next_element( ber, &len, last ) )
{
- if ( *bv == NULL ) {
- *bv = (struct berval **) malloc(
- 2 * sizeof(struct berval *) );
- } else {
- *bv = (struct berval **) realloc( *bv,
- (j + 2) * sizeof(struct berval *) );
- }
+ *bv = (struct berval **) LBER_REALLOC( *bv,
+ (j + 2) * sizeof(struct berval *) );
+
rc = ber_get_stringal( ber, &((*bv)[j]) );
j++;
}
case 'a': /* octet string - allocate storage as needed */
ss = va_arg( ap, char ** );
if ( *ss ) {
- free( *ss );
+ LBER_FREE( *ss );
*ss = NULL;
}
break;
case 'o': /* octet string in a supplied berval */
bval = va_arg( ap, struct berval * );
if ( bval->bv_val != NULL ) {
- free( bval->bv_val );
+ LBER_FREE( bval->bv_val );
bval->bv_val = NULL;
}
bval->bv_len = 0;
case 'B': /* bit string - allocate storage as needed */
ss = va_arg( ap, char ** );
if ( *ss ) {
- free( *ss );
+ LBER_FREE( *ss );
*ss = NULL;
}
*(va_arg( ap, long * )) = 0; /* for length, in bits */
sss = va_arg( ap, char *** );
if ( *sss ) {
for (j = 0; (*sss)[j]; j++) {
- free( (*sss)[j] );
+ LBER_FREE( (*sss)[j] );
(*sss)[j] = NULL;
}
- free( *sss );
+ LBER_FREE( *sss );
*sss = NULL;
}
break;
assert(bv != NULL); /* bv damn better point to something */
if ( bv->bv_val != NULL )
- free( bv->bv_val );
- free( (char *) bv );
+ LBER_FREE( bv->bv_val );
+ LBER_FREE( (char *) bv );
}
void
for ( i = 0; bv[i] != NULL; i++ )
ber_bvfree( bv[i] );
- free( (char *) bv );
+ LBER_FREE( (char *) bv );
}
struct berval *
return NULL;
}
- if ( (new = (struct berval *) malloc( sizeof(struct berval) ))
+ if ( (new = (struct berval *) LBER_MALLOC( sizeof(struct berval) ))
== NULL ) {
return( NULL );
}
return ( new );
}
- if ( (new->bv_val = (char *) malloc( bv->bv_len + 1 )) == NULL ) {
- free( new );
+ if ( (new->bv_val = (char *) LBER_MALLOC( bv->bv_len + 1 )) == NULL ) {
+ LBER_FREE( new );
return( NULL );
}
#ifdef STR_TRANSLATION
if ( free_str ) {
- free( str );
+ LBER_FREE( str );
}
#endif /* STR_TRANSLATION */
assert( ber != NULL );
assert( BER_VALID( ber ) );
- if ( (new = (Seqorset *) calloc( sizeof(Seqorset), 1 ))
- == NULLSEQORSET )
+ new = (Seqorset *) LBER_CALLOC( 1, sizeof(Seqorset) );
+
+ if ( new == NULLSEQORSET )
return( -1 );
+
new->sos_ber = ber;
if ( ber->ber_sos == NULLSEQORSET )
new->sos_first = ber->ber_ptr;
}
/* we're done with this seqorset, so free it up */
- free( (char *) (*sos) );
+ LBER_FREE( (char *) (*sos) );
*sos = next;
return( taglen + lenlen + len );
oldbuf = ber->ber_buf;
+ ber->ber_buf = (char *) LBER_REALLOC( ber->ber_buf, total );
+
if ( ber->ber_buf == NULL ) {
- if ( (ber->ber_buf = (char *) malloc( (size_t)total )) == NULL )
- return( -1 );
- } else if ( (ber->ber_buf = (char *) realloc( ber->ber_buf,
- (size_t)total )) == NULL )
+ ber->ber_buf = oldbuf;
return( -1 );
+ }
ber->ber_end = ber->ber_buf + total;
assert( BER_VALID( ber ) );
if ( freebuf && ber->ber_buf != NULL )
- free( ber->ber_buf );
+ LBER_FREE( ber->ber_buf );
ber->ber_buf = NULL;
ber->ber_valid = LBER_UNINITIALIZED;
- free( (char *) ber );
+ LBER_FREE( (char *) ber );
}
int
{
BerElement *ber;
- ber = (BerElement *) calloc( 1, sizeof(BerElement) );
+ ber = (BerElement *) LBER_CALLOC( 1, sizeof(BerElement) );
if ( ber == NULLBER )
return( NULLBER );
return( -1 );
}
- if ( (bv = malloc( sizeof(struct berval))) == NULL ) {
+ if ( (bv = LBER_MALLOC( sizeof(struct berval))) == NULL ) {
return( -1 );
}
/* copy the berval */
ptrdiff_t len = ber->ber_ptr - ber->ber_buf;
- if ( (bv->bv_val = (char *) malloc( len + 1 )) == NULL ) {
+ if ( (bv->bv_val = (char *) LBER_MALLOC( len + 1 )) == NULL ) {
ber_bvfree( bv );
return( -1 );
}
errno = ERANGE;
return LBER_DEFAULT;
}
- ber->ber_buf = (char *) malloc( ber->ber_len );
+ ber->ber_buf = (char *) LBER_MALLOC( ber->ber_len );
if (ber->ber_buf==NULL)
return LBER_DEFAULT;
ber->ber_rwptr = ber->ber_buf;
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))
+
/* sockbuf.c */
/* these should be ber_int*() functions */
# End Source File
# Begin Source File
+SOURCE=.\memory.c
+# End Source File
+# Begin Source File
+
SOURCE=.\options.c
# End Source File
# Begin Source File
--- /dev/null
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+#include "portable.h"
+
+#include <stdlib.h>
+
+#include "lber-int.h"
+
+void
+ber_memfree( void *p )
+{
+ LBER_FREE( p );
+}
+
+void *
+ber_memalloc( size_t s )
+{
+ return LBER_MALLOC( s );
+}
+
+void *
+ber_memcalloc( size_t n, size_t s )
+{
+ return LBER_CALLOC( n, s );
+}
+
+void *
+ber_memrealloc( void* p, size_t s )
+{
+ return LBER_REALLOC( p, s );
+}
+
if ((buf->buf_base==NULL) || ((buf->buf_end==0) && (buf->buf_ptr==0))) {
/* empty buffer */
if (buf->buf_base!=NULL)
- free( buf->buf_base );
+ LBER_FREE( buf->buf_base );
assert( buf->buf_ptr==0 );
assert( buf->buf_end==0 );
- buf->buf_base = malloc( minsize );
+ buf->buf_base = LBER_MALLOC( minsize );
if (buf->buf_base==NULL)
return -1;
} else {
char *nb;
- nb = realloc( buf->buf_base, minsize );
+ nb = LBER_REALLOC( buf->buf_base, minsize );
if (nb==NULL)
return -1;
buf->buf_base = nb;
Sockbuf *ber_sockbuf_alloc( void )
{
- Sockbuf *sb = calloc(1, sizeof(Sockbuf));
+ Sockbuf *sb = LBER_CALLOC(1, sizeof(Sockbuf));
if( sb == NULL ) return NULL;
assert(sb != NULL);
assert( SOCKBUF_VALID( sb ) );
ber_pvt_sb_destroy( sb );
- free(sb);
+ LBER_FREE(sb);
}
long
assert( buf != NULL);
if (buf->buf_base)
- free( buf->buf_base );
+ LBER_FREE( buf->buf_base );
sockbuf_buf_init( buf );
return 0;
}
assert( sb != NULL);
assert( SOCKBUF_VALID( sb ) );
- sb->sb_iodata = malloc( sizeof( struct dgram_data ) );
+ sb->sb_iodata = LBER_MALLOC( sizeof( struct dgram_data ) );
if (sb->sb_iodata==NULL)
return -1;
sb->sb_read_ahead = 1; /* important since udp is packet based. */
assert( sb != NULL);
assert( SOCKBUF_VALID( sb ) );
- free( sb->sb_iodata );
+ LBER_FREE( sb->sb_iodata );
return 0;
}
{
BerElement *ber;
int i, err, sendabandon;
+ unsigned long *old_abandon;
Sockbuf *sb;
LDAPRequest *lr;
}
}
- if ( ld->ld_abandoned == NULL ) {
- if ( (ld->ld_abandoned = (int *) malloc( 2 * sizeof(int) ))
- == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( ld->ld_errno );
- }
- i = 0;
- } else {
- for ( i = 0; ld->ld_abandoned[i] != -1; i++ )
+ i = 0;
+ if ( ld->ld_abandoned != NULL ) {
+ for ( ; ld->ld_abandoned[i] != -1; i++ )
; /* NULL */
- if ( (ld->ld_abandoned = (int *) realloc( (char *)
- ld->ld_abandoned, (i + 2) * sizeof(int) )) == NULL ) {
- ld->ld_errno = LDAP_NO_MEMORY;
- return( ld->ld_errno );
- }
}
+
+ old_abandon = ld->ld_abandoned;
+
+ ld->ld_abandoned = (int *) LDAP_REALLOC( (char *)
+ ld->ld_abandoned, (i + 2) * sizeof(int) );
+
+ if ( ld->ld_abandoned == NULL ) {
+ ld->ld_abandoned = old_abandon;
+ ld->ld_errno = LDAP_NO_MEMORY;
+ return( ld->ld_errno );
+ }
+
ld->ld_abandoned[i] = msgid;
ld->ld_abandoned[i + 1] = -1;
{
#ifndef LDAP_NOCACHE
if ( ld->ld_cache == NULLLDCACHE ) {
- if (( ld->ld_cache = (LDAPCache *)malloc( sizeof( LDAPCache )))
+ if (( ld->ld_cache = (LDAPCache *)LDAP_MALLOC( sizeof( LDAPCache )))
== NULLLDCACHE ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( -1 );
#ifndef LDAP_NOCACHE
if ( ld->ld_cache != NULLLDCACHE ) {
ldap_flush_cache( ld );
- free( (char *)ld->ld_cache );
+ LDAP_FREE( (char *)ld->ld_cache );
ld->ld_cache = NULLLDCACHE;
}
#endif
return;
}
- if (( new = (LDAPMessage *) calloc( 1, sizeof(LDAPMessage) ))
+ if (( new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) ))
!= NULL ) {
if (( new->lm_ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
- free( (char *)new );
+ LDAP_FREE( (char *)new );
return;
}
len = request->ber_ptr - request->ber_buf;
- if (( new->lm_ber->ber_buf = (char *) malloc( (size_t)len ))
+ if (( new->lm_ber->ber_buf = (char *) ber_memalloc( (size_t)len ))
== NULL ) {
ber_free( new->lm_ber, 0 );
- free( (char *)new );
+ LDAP_FREE( (char *)new );
ld->ld_errno = LDAP_NO_MEMORY;
return;
}
LDAPMessage *new;
long len;
- if (( new = (LDAPMessage *)malloc( sizeof(LDAPMessage))) != NULL ) {
+ if (( new = (LDAPMessage *)LDAP_MALLOC( sizeof(LDAPMessage))) != NULL ) {
*new = *msg; /* struct copy */
if (( new->lm_ber = ber_dup( msg->lm_ber )) == NULLBER ) {
- free( (char *)new );
+ LDAP_FREE( (char *)new );
return( NULLMSG );
}
len = msg->lm_ber->ber_end - msg->lm_ber->ber_buf;
- if (( new->lm_ber->ber_buf = (char *) malloc(
+ if (( new->lm_ber->ber_buf = (char *) ber_memalloc(
(size_t)len )) == NULL ) {
ber_free( new->lm_ber, 0 );
- free( (char *)new );
+ LDAP_FREE( (char *)new );
return( NULLMSG );
}
SAFEMEMCPY( new->lm_ber->ber_buf, msg->lm_ber->ber_buf,
ber = *msg->lm_ber; /* struct copy */
if ( ber_scanf( &ber, "{i{a", &msgid, &s ) != LBER_ERROR ) {
rc = ( strcasecmp( dn, s ) == 0 ) ? 1 : 0;
- free( s );
+ LDAP_FREE( s );
if ( rc != 0 ) {
return( rc );
}
ber = *m->lm_ber; /* struct copy */
if ( ber_scanf( &ber, "{a", &s ) != LBER_ERROR ) {
rc = ( strcasecmp( dn, s ) == 0 ) ? 1 : 0;
- free( s );
+ LDAP_FREE( s );
}
}
len = *buflenp;
s = (Byte *) *bufp;
- if ( (o = oo = (Byte *)malloc( 2 * len + 64 )) == NULL ) {
+ if ( (o = oo = (Byte *)LDAP_MALLOC( 2 * len + 64 )) == NULL ) {
return( 1 );
}
len = o - oo;
o = oo;
- if ( (oo = (Byte *)realloc( o, len )) == NULL ) {
- free( o );
+ if ( (oo = (Byte *)LDAP_REALLOC( o, len )) == NULL ) {
+ LDAP_FREE( o );
return( 1 );
}
if ( free_input ) {
- free( *bufp );
+ LDAP_FREE( *bufp );
}
*bufp = (char *) oo;
*buflenp = len;
len = *buflenp;
s = (Byte *) *bufp;
- if ( (o = oo = (Byte *)malloc( 2 * len + 64 )) == NULL ) {
+ if ( (o = oo = (Byte *)LDAP_MALLOC( 2 * len + 64 )) == NULL ) {
return( 1 );
}
len = o - oo;
o = oo;
- if ( (oo = (Byte *)realloc( o, len )) == NULL ) {
- free( o );
+ if ( (oo = (Byte *)LDAP_REALLOC( o, len )) == NULL ) {
+ LDAP_FREE( o );
return( 1 );
}
if ( free_input ) {
- free( *bufp );
+ LDAP_FREE( *bufp );
}
*bufp = (char *) oo;
*buflenp = len;
Byte *o, *oo;
Byte n;
- if ( (o = oo = (Byte *)malloc( 2 * strlen( s ) + 64 )) == NULL ) {
+ if ( (o = oo = (Byte *)LDAP_MALLOC( 2 * strlen( s ) + 64 )) == NULL ) {
return( NULL );
}
o = oo;
- if ( (oo = (Byte *)realloc( o, strlen( o ) + 1 )) == NULL ) {
- free( o );
+ if ( (oo = (Byte *)LDAP_REALLOC( o, strlen( o ) + 1 )) == NULL ) {
+ LDAP_FREE( o );
return( NULL );
}
Byte n;
const Couple *cc;
- if ( (o = oo = (Byte *)malloc( 2 * strlen( s ) + 64 )) == NULL ) {
+ if ( (o = oo = (Byte *)LDAP_MALLOC( 2 * strlen( s ) + 64 )) == NULL ) {
return( NULL );
}
o = oo;
- if ( (oo = (Byte *)realloc( o, strlen( o ) + 1 )) == NULL ) {
- free( o );
+ if ( (oo = (Byte *)LDAP_REALLOC( o, strlen( o ) + 1 )) == NULL ) {
+ LDAP_FREE( o );
return( NULL );
}
int local_h_errno;
char *ha_buf=NULL;
-#define DO_RETURN(x) if (ha_buf) free(ha_buf); return (x);
+#define DO_RETURN(x) if (ha_buf) LDAP_FREE(ha_buf); return (x);
Debug( LDAP_DEBUG_TRACE, "ldap_open\n", 0, 0, 0 );
{
struct sockaddr *newsap, **addrs;
- if (( newsap = (struct sockaddr *)malloc( sizeof( struct sockaddr )))
+ if (( newsap = (struct sockaddr *)LDAP_MALLOC( sizeof( struct sockaddr )))
== NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( -1 );
}
- if ( ld->ld_cldapnaddr == 0 ) {
- addrs = (struct sockaddr **)malloc( sizeof(struct sockaddr *));
- } else {
- addrs = (struct sockaddr **)realloc( ld->ld_cldapaddrs,
+ addrs = (struct sockaddr **)LDAP_REALLOC( ld->ld_cldapaddrs,
( ld->ld_cldapnaddr + 1 ) * sizeof(struct sockaddr *));
- }
if ( addrs == NULL ) {
- free( newsap );
+ LDAP_FREE( newsap );
ld->ld_errno = LDAP_NO_MEMORY;
return( -1 );
}
logdn = NULL;
if ( ber_scanf( &ber, "ia", &id, &logdn ) == LBER_ERROR ) {
- free( ber.ber_buf ); /* gack! */
+ LDAP_FREE( ber.ber_buf ); /* gack! */
ret = LDAP_DECODING_ERROR;
Debug( LDAP_DEBUG_TRACE,
"cldap_result: ber_scanf returned LBER_ERROR (%d)\n",
ret, 0, 0 );
} else if ( id != msgid ) {
- free( ber.ber_buf ); /* gack! */
+ LDAP_FREE( ber.ber_buf ); /* gack! */
Debug( LDAP_DEBUG_TRACE,
"cldap_result: looking for msgid %d; got %d\n",
msgid, id, 0 );
}
}
ret = cldap_parsemsg( ld, msgid, &ber, res, base );
- free( ber.ber_buf ); /* gack! */
+ LDAP_FREE( ber.ber_buf ); /* gack! */
Debug( LDAP_DEBUG_TRACE,
"cldap_result got result (%d)\n", ret, 0, 0 );
}
if ( logdn != NULL ) {
- free( logdn );
+ LDAP_FREE( logdn );
}
}
for ( tag = ber_first_element( ber, &len, &cookie );
tag != LBER_DEFAULT && rc != LDAP_SUCCESS;
tag = ber_next_element( ber, &len, cookie )) {
- if (( ldm = (LDAPMessage *)calloc( 1, sizeof(LDAPMessage)))
+ if (( ldm = (LDAPMessage *)LDAP_CALLOC( 1, sizeof(LDAPMessage)))
== NULL || ( ldm->lm_ber = ldap_alloc_ber_with_options( ld ))
== NULLBER ) {
rc = LDAP_NO_MEMORY;
/*
* substitute original searchbase for trailing '*'
*/
- if (( p = (char *)malloc( slen + baselen )) == NULL ) {
+ if (( p = (char *)LDAP_MALLOC( slen + baselen )) == NULL ) {
rc = LDAP_NO_MEMORY;
- free( dn );
+ LDAP_FREE( dn );
break; /* return w/error */
}
strcpy( p, dn );
strcpy( p + slen - 1, base );
- free( dn );
+ LDAP_FREE( dn );
dn = p;
}
bv->bv_len ) == -1 ) {
break; /* return w/error */
}
- free( dn );
+ LDAP_FREE( dn );
ber_bvfree( bv );
bv = NULL;
if ( ldm->lm_ber != NULLBER ) {
ber_free( ldm->lm_ber, 1 );
}
- free( ldm );
+ LDAP_FREE( ldm );
}
if ( bv != NULL ) {
ber_bvfree( bv );
/* set through each element */
nctrls = 0;
- *ctrls = malloc( 1 * sizeof(LDAPControl *) );
+ *ctrls = LDAP_MALLOC( 1 * sizeof(LDAPControl *) );
if( *ctrls == NULL ) {
return LDAP_NO_MEMORY;
LDAPControl *tctrl;
LDAPControl **tctrls;
- tctrl = calloc( 1, sizeof(LDAPControl) );
+ tctrl = LDAP_CALLOC( 1, sizeof(LDAPControl) );
/* allocate pointer space for current controls (nctrls)
* + this control + extra NULL
*/
tctrls = (tctrl == NULL) ? NULL :
- realloc(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
+ LDAP_REALLOC(*ctrls, (nctrls+2) * sizeof(LDAPControl *));
if( tctrls == NULL ) {
/* one of the above allocation failed */
if( tctrl != NULL ) {
- free( tctrl );
+ LDAP_FREE( tctrl );
}
ldap_controls_free(*ctrls);
{
if ( c != NULL ) {
if( c->ldctl_oid != NULL) {
- free( c->ldctl_oid );
+ LDAP_FREE( c->ldctl_oid );
}
if( c->ldctl_value.bv_val != NULL ) {
- free( c->ldctl_value.bv_val );
+ LDAP_FREE( c->ldctl_value.bv_val );
}
- free( c );
+ LDAP_FREE( c );
}
}
ldap_control_free( c );
}
- free( controls );
+ LDAP_FREE( controls );
}
}
return NULL;
}
- new = (LDAPControl **) malloc( i * sizeof(LDAPControl *) );
+ new = (LDAPControl **) LDAP_MALLOC( i * sizeof(LDAPControl *) );
if( new == NULL ) {
/* memory allocation failure */
return NULL;
}
- new = (LDAPControl *) malloc( sizeof(LDAPControl) );
+ new = (LDAPControl *) LDAP_MALLOC( sizeof(LDAPControl) );
if( new == NULL ) {
return NULL;
new->ldctl_oid = strdup( c->ldctl_oid );
if(new->ldctl_oid == NULL) {
- free( new );
+ LDAP_FREE( new );
return NULL;
}
}
if( c->ldctl_value.bv_len > 0 ) {
- new->ldctl_value.bv_val = (char *) malloc( c->ldctl_value.bv_len );
+ new->ldctl_value.bv_val = (char *) LDAP_MALLOC( c->ldctl_value.bv_len );
if(new->ldctl_value.bv_val == NULL) {
if(new->ldctl_oid != NULL) {
- free( new->ldctl_oid );
+ LDAP_FREE( new->ldctl_oid );
}
- free( new );
+ LDAP_FREE( new );
return NULL;
}
return( LDAP_TMPL_ERR_FILE );
}
- if (( buf = malloc( (size_t)len )) == NULL ) {
+ if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) {
fclose( fp );
return( LDAP_TMPL_ERR_MEM );
}
fclose( fp );
if ( rlen != len && !eof ) { /* error: didn't get the whole file */
- free( buf );
+ LDAP_FREE( buf );
return( LDAP_TMPL_ERR_FILE );
}
rc = ldap_init_templates_buf( buf, rlen, tmpllistp );
- free( buf );
+ LDAP_FREE( buf );
return( rc );
}
{
if ( tmpl != NULL ) {
if ( tmpl->dt_name != NULL ) {
- free( tmpl->dt_name );
+ LDAP_FREE( tmpl->dt_name );
}
if ( tmpl->dt_pluralname != NULL ) {
- free( tmpl->dt_pluralname );
+ LDAP_FREE( tmpl->dt_pluralname );
}
if ( tmpl->dt_iconname != NULL ) {
- free( tmpl->dt_iconname );
+ LDAP_FREE( tmpl->dt_iconname );
}
if ( tmpl->dt_authattrname != NULL ) {
- free( tmpl->dt_authattrname );
+ LDAP_FREE( tmpl->dt_authattrname );
}
if ( tmpl->dt_defrdnattrname != NULL ) {
- free( tmpl->dt_defrdnattrname );
+ LDAP_FREE( tmpl->dt_defrdnattrname );
}
if ( tmpl->dt_defaddlocation != NULL ) {
- free( tmpl->dt_defaddlocation );
+ LDAP_FREE( tmpl->dt_defaddlocation );
}
if ( tmpl->dt_oclist != NULL ) {
for ( ocp = tmpl->dt_oclist; ocp != NULL; ocp = nextocp ) {
nextocp = ocp->oc_next;
free_strarray( ocp->oc_objclasses );
- free( ocp );
+ LDAP_FREE( ocp );
}
}
for ( adp = tmpl->dt_adddeflist; adp != NULL; adp = nextadp ) {
nextadp = adp->ad_next;
if( adp->ad_attrname != NULL ) {
- free( adp->ad_attrname );
+ LDAP_FREE( adp->ad_attrname );
}
if( adp->ad_value != NULL ) {
- free( adp->ad_value );
+ LDAP_FREE( adp->ad_value );
}
- free( adp );
+ LDAP_FREE( adp );
}
}
for ( colp = rowp; colp != NULL; colp = nextcolp ) {
nextcolp = colp->ti_next_in_row;
if ( colp->ti_attrname != NULL ) {
- free( colp->ti_attrname );
+ LDAP_FREE( colp->ti_attrname );
}
if ( colp->ti_label != NULL ) {
- free( colp->ti_label );
+ LDAP_FREE( colp->ti_label );
}
if ( colp->ti_args != NULL ) {
free_strarray( colp->ti_args );
}
- free( colp );
+ LDAP_FREE( colp );
}
}
}
- free( tmpl );
+ LDAP_FREE( tmpl );
}
}
attrcnt = 0;
memerr = 0;
- if (( attrs = (char **)malloc( sizeof( char * ))) == NULL ) {
+ if (( attrs = (char **)LDAP_MALLOC( sizeof( char * ))) == NULL ) {
return( NULL );
}
if ( includeattrs != NULL ) {
for ( i = 0; !memerr && includeattrs[ i ] != NULL; ++i ) {
- if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) *
+ if (( attrs = (char **)LDAP_REALLOC( attrs, ( attrcnt + 2 ) *
sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] =
strdup( includeattrs[ i ] )) == NULL ) {
memerr = 1;
}
if ( ticolp->ti_attrname != NULL ) {
- if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) *
+ if (( attrs = (char **)LDAP_REALLOC( attrs, ( attrcnt + 2 ) *
sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] =
strdup( ticolp->ti_attrname )) == NULL ) {
memerr = 1;
if ( memerr || attrcnt == 0 ) {
for ( i = 0; i < attrcnt; ++i ) {
if ( attrs[ i ] != NULL ) {
- free( attrs[ i ] );
+ LDAP_FREE( attrs[ i ] );
}
}
- free( (char *)attrs );
+ LDAP_FREE( (char *)attrs );
return( NULL );
}
return( tokcnt == 0 ? 0 : LDAP_TMPL_ERR_SYNTAX );
}
- if (( tmpl = (struct ldap_disptmpl *)calloc( 1,
+ if (( tmpl = (struct ldap_disptmpl *)LDAP_CALLOC( 1,
sizeof( struct ldap_disptmpl ))) == NULL ) {
free_strarray( toks );
return( LDAP_TMPL_ERR_MEM );
}
tmpl->dt_name = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* template plural name comes next
return( LDAP_TMPL_ERR_SYNTAX );
}
tmpl->dt_pluralname = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* template icon name is next
return( LDAP_TMPL_ERR_SYNTAX );
}
tmpl->dt_iconname = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* template options come next
* object class list is next
*/
while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
- if (( ocp = (struct ldap_oclist *)calloc( 1,
+ if (( ocp = (struct ldap_oclist *)LDAP_CALLOC( 1,
sizeof( struct ldap_oclist ))) == NULL ) {
free_strarray( toks );
free_disptmpl( tmpl );
if ( toks[ 0 ][ 0 ] != '\0' ) {
tmpl->dt_authattrname = toks[ 0 ];
} else {
- free( toks[ 0 ] );
+ LDAP_FREE( toks[ 0 ] );
}
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* read default attribute to use for RDN
return( LDAP_TMPL_ERR_SYNTAX );
}
tmpl->dt_defrdnattrname = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* read default location for new entries
if ( toks[ 0 ][ 0 ] != '\0' ) {
tmpl->dt_defaddlocation = toks[ 0 ];
} else {
- free( toks[ 0 ] );
+ LDAP_FREE( toks[ 0 ] );
}
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* read list of rules used to define default values for new entries
return( LDAP_TMPL_ERR_SYNTAX );
}
- if (( adp = (struct ldap_adddeflist *)calloc( 1,
+ if (( adp = (struct ldap_adddeflist *)LDAP_CALLOC( 1,
sizeof( struct ldap_adddeflist ))) == NULL ) {
free_strarray( toks );
free_disptmpl( tmpl );
if ( adsource == LDAP_ADSRC_CONSTANTVALUE ) {
adp->ad_value = toks[ 2 ];
}
- free( toks[ 0 ] );
- free( (char *)toks );
+ LDAP_FREE( toks[ 0 ] );
+ LDAP_FREE( (char *)toks );
if ( tmpl->dt_adddeflist == NULL ) {
tmpl->dt_adddeflist = adp;
return( LDAP_TMPL_ERR_SYNTAX );
}
- if (( ip = (struct ldap_tmplitem *)calloc( 1,
+ if (( ip = (struct ldap_tmplitem *)LDAP_CALLOC( 1,
sizeof( struct ldap_tmplitem ))) == NULL ) {
free_strarray( toks );
free_disptmpl( tmpl );
return( LDAP_TMPL_ERR_SYNTAX );
}
- free( toks[ 0 ] );
- free( toks[ 1 ] );
+ LDAP_FREE( toks[ 0 ] );
+ LDAP_FREE( toks[ 1 ] );
ip->ti_syntaxid = itemsynids[ i ];
ip->ti_label = toks[ 2 ];
if ( toks[ 3 ][ 0 ] == '\0' ) {
ip->ti_attrname = NULL;
- free( toks[ 3 ] );
+ LDAP_FREE( toks[ 3 ] );
} else {
ip->ti_attrname = toks[ 3 ];
}
for ( i = 0; toks[ i + 4 ] != NULL; ++i ) {
;
}
- if (( ip->ti_args = (char **) calloc( i + 1, sizeof( char * )))
+ if (( ip->ti_args = (char **) LDAP_CALLOC( i + 1, sizeof( char * )))
== NULL ) {
free_disptmpl( tmpl );
return( LDAP_TMPL_ERR_MEM );
ip->ti_args[ i ] = toks[ i + 4 ];
}
}
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
if ( tmpl->dt_items == NULL ) {
tmpl->dt_items = rowp = ip;
return( rc );
}
- if (( toks = (char **)calloc( 1, sizeof( char * ))) == NULL ) {
- free( line );
+ if (( toks = (char **)LDAP_CALLOC( 1, sizeof( char * ))) == NULL ) {
+ LBER_FREE( line );
return( -1 );
}
tokcnt = 0;
p = line;
while (( token = next_token( &p )) != NULL ) {
- if (( toks = (char **)realloc( toks, ( tokcnt + 2 ) *
+ if (( toks = (char **)LDAP_REALLOC( toks, ( tokcnt + 2 ) *
sizeof( char * ))) == NULL ) {
- free( (char *)toks );
- free( line );
+ LBER_FREE( (char *)toks );
+ LBER_FREE( line );
return( -1 );
}
toks[ tokcnt ] = token;
toks = NULL;
}
- free( line );
+ LBER_FREE( line );
if ( tokcnt == 0 ) {
if ( toks != NULL ) {
- free( (char *)toks );
+ LBER_FREE( (char *)toks );
}
} else {
*toksp = toks;
return( 0 ); /* end of file */
}
- if (( line = malloc( p - linestart )) == NULL ) {
+ if (( line = LDAP_MALLOC( p - linestart )) == NULL ) {
*linep = NULL;
return( -1 ); /* fatal error */
}
if ( sap != NULL ) {
for ( i = 0; sap[ i ] != NULL; ++i ) {
- free( sap[ i ] );
+ LBER_FREE( sap[ i ] );
}
- free( (char *)sap );
+ LBER_FREE( (char *)sap );
}
}
; /* NULL */
if ( ld->ld_error ) {
- free( ld->ld_error );
+ LDAP_FREE( ld->ld_error );
ld->ld_error = NULL;
}
if ( ld->ld_matched ) {
- free( ld->ld_matched );
+ LDAP_FREE( ld->ld_matched );
ld->ld_matched = NULL;
}
void
ldap_memfree( void *p )
{
- if(p != NULL) {
- free( p );
- }
+ LDAP_FREE( p );
+}
+
+void *
+ldap_memalloc( size_t s )
+{
+ return LDAP_MALLOC( s );
+}
+
+void *
+ldap_memcalloc( size_t n, size_t s )
+{
+ return LDAP_CALLOC( n, s );
+}
+
+void *
+ldap_memrealloc( void* p, size_t s )
+{
+ return LDAP_REALLOC( p, s );
}
void
for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
nextfip = fip->lfi_next;
- free( fip->lfi_filter );
- free( fip->lfi_desc );
- free( fip );
+ LDAP_FREE( fip->lfi_filter );
+ LDAP_FREE( fip->lfi_desc );
+ LDAP_FREE( fip );
}
nextflp = flp->lfl_next;
- free( flp->lfl_pattern );
- free( flp->lfl_delims );
- free( flp->lfl_tag );
- free( flp );
+ LDAP_FREE( flp->lfl_pattern );
+ LDAP_FREE( flp->lfl_delims );
+ LDAP_FREE( flp->lfl_tag );
+ LDAP_FREE( flp );
}
if ( lfdp->lfd_curvalcopy != NULL ) {
- free( lfdp->lfd_curvalcopy );
+ LDAP_FREE( lfdp->lfd_curvalcopy );
}
if ( lfdp->lfd_curvalwords != NULL ) {
- free( lfdp->lfd_curvalwords );
+ LDAP_FREE( lfdp->lfd_curvalwords );
}
if ( lfdp->lfd_filtprefix != NULL ) {
- free( lfdp->lfd_filtprefix );
+ LDAP_FREE( lfdp->lfd_filtprefix );
}
if ( lfdp->lfd_filtsuffix != NULL ) {
- free( lfdp->lfd_filtsuffix );
+ LDAP_FREE( lfdp->lfd_filtsuffix );
}
- free( lfdp );
+ LDAP_FREE( lfdp );
}
/*
} else {
ldap_value_free( mods[i]->mod_values );
}
- free( (char *) mods[i] );
+ LDAP_FREE( (char *) mods[i] );
}
if ( freemods )
- free( (char *) mods );
+ LDAP_FREE( (char *) mods );
}
}
rewind( fp );
- if ( (*map = (LDAPFriendlyMap *) malloc( (entries + 1) *
+ if ( (*map = (LDAPFriendlyMap *) LDAP_MALLOC( (entries + 1) *
sizeof(LDAPFriendlyMap) )) == NULL ) {
fclose( fp );
return( uname );
while ( pF->lf_unfriendly )
{
- free( pF->lf_unfriendly );
- free( pF->lf_friendly );
+ LDAP_FREE( pF->lf_unfriendly );
+ LDAP_FREE( pF->lf_friendly );
pF++;
}
- free( *map );
+ LDAP_FREE( *map );
*map = NULL;
}
return( NULL );
}
- if ( (rdns = (char **) malloc( maxcomps * sizeof(char *) )) == NULL ) {
- free( dn );
+ if ( (rdns = (char **) LDAP_MALLOC( maxcomps * sizeof(char *) )) == NULL ) {
+ LDAP_FREE( dn );
return( NULL );
}
{
if ( ncomps == maxcomps ) {
maxcomps *= 2;
- if ( (rdns = (char **) realloc( rdns, maxcomps *
+ if ( (rdns = (char **) LDAP_REALLOC( rdns, maxcomps *
sizeof(char *) )) == NULL )
{
- free( dn );
+ LDAP_FREE( dn );
return NULL;
}
}
rdns[ncomps++] = strdup( s );
}
- free(dn);
+ LDAP_FREE(dn);
rdns[ncomps] = NULL;
/* trim rdns */
- rdns = (char **) realloc( rdns, (ncomps+1) * sizeof(char*) );
+ rdns = (char **) LDAP_REALLOC( rdns, (ncomps+1) * sizeof(char*) );
return( rdns );
}
if ( state == OUTQUOTE ) {
++count;
if ( parts == NULL ) {
- if (( parts = (char **)malloc( 8
+ if (( parts = (char **)LDAP_MALLOC( 8
* sizeof( char *))) == NULL )
return( NULL );
} else if ( count >= 8 ) {
- if (( parts = (char **)realloc( parts,
+ if (( parts = (char **)LDAP_REALLOC( parts,
(count+1) * sizeof( char *)))
== NULL )
return( NULL );
}
len = p - name;
- if (( parts[ count-1 ] = (char *)calloc( 1,
+ if (( parts[ count-1 ] = (char *)LDAP_CALLOC( 1,
len + 1 )) != NULL ) {
SAFEMEMCPY( parts[ count-1 ], name,
len );
/*
* punt: return list conisting of the original domain name only
*/
- if (( dxs = (char **)malloc( 2 * sizeof( char * ))) == NULL ||
+ if (( dxs = (char **)LDAP_MALLOC( 2 * sizeof( char * ))) == NULL ||
( dxs[ 0 ] = strdup( domain )) == NULL ) {
if ( dxs != NULL ) {
- free( dxs );
+ LDAP_FREE( dxs );
}
dxs = NULL;
} else {
++r;
--txt_len;
}
- if ( dx_count == 0 ) {
- dxs = (char **)malloc( 2 * sizeof( char * ));
- } else {
- dxs = (char **)realloc( dxs,
+ dxs = (char **)LDAP_REALLOC( dxs,
( dx_count + 2 ) * sizeof( char * ));
- }
if ( dxs == NULL || ( dxs[ dx_count ] =
- (char *)calloc( 1, txt_len + 1 )) == NULL ) {
+ (char *)LDAP_CALLOC( 1, txt_len + 1 )) == NULL ) {
err = NO_RECOVERY;
continue;
}
if( rc != LDAP_SUCCESS ) {
ld->ld_errno = rc;
- if( ld->ld_matched != NULL )
- free( ld->ld_matched );
-
- ld->ld_matched = NULL;
-
- if( ld->ld_error != NULL )
- free( ld->ld_error );
+ if( ld->ld_matched != NULL ) {
+ LDAP_FREE( ld->ld_matched );
+ ld->ld_matched = NULL;
+ }
- ld->ld_error = NULL;
+ if( ld->ld_error != NULL ) {
+ LDAP_FREE( ld->ld_error );
+ ld->ld_error = NULL;
+ }
}
return rc;
return( NULL );
}
- if (( buf = malloc( (size_t)len )) == NULL ) {
+ if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) {
fclose( fp );
return( NULL );
}
fclose( fp );
if ( rlen != len && !eof ) { /* error: didn't get the whole file */
- free( buf );
+ LDAP_FREE( buf );
return( NULL );
}
lfdp = ldap_init_getfilter_buf( buf, rlen );
- free( buf );
+ LDAP_FREE( buf );
return( lfdp );
}
int rc;
regex_t re;
- if (( lfdp = (LDAPFiltDesc *)calloc( 1, sizeof( LDAPFiltDesc))) == NULL ) {
+ if (( lfdp = (LDAPFiltDesc *)LDAP_CALLOC( 1, sizeof( LDAPFiltDesc))) == NULL ) {
return( NULL );
}
switch( tokcnt ) {
case 1: /* tag line */
if ( tag != NULL ) {
- free( tag );
+ LDAP_FREE( tag );
}
tag = tok[ 0 ];
- free( tok );
+ LDAP_FREE( tok );
break;
case 4:
case 5: /* start of filter info. list */
- if (( nextflp = (LDAPFiltList *)calloc( 1, sizeof( LDAPFiltList )))
+ if (( nextflp = (LDAPFiltList *)LDAP_CALLOC( 1, sizeof( LDAPFiltList )))
== NULL ) {
ldap_getfilter_free( lfdp );
return( NULL );
case 2:
case 3: /* filter, desc, and optional search scope */
if ( nextflp != NULL ) { /* add to info list */
- if (( nextfip = (LDAPFiltInfo *)calloc( 1,
+ if (( nextfip = (LDAPFiltInfo *)LDAP_CALLOC( 1,
sizeof( LDAPFiltInfo ))) == NULL ) {
ldap_getfilter_free( lfdp );
free_strarray( tok );
errno = EINVAL;
return( NULL );
}
- free( tok[ 2 ] );
+ LDAP_FREE( tok[ 2 ] );
tok[ 2 ] = NULL;
} else {
nextfip->lfi_scope = LDAP_SCOPE_SUBTREE; /* default */
}
nextfip->lfi_isexact = ( strchr( tok[ 0 ], '*' ) == NULL &&
strchr( tok[ 0 ], '~' ) == NULL );
- free( tok );
+ LDAP_FREE( tok );
}
break;
}
if ( tag != NULL ) {
- free( tag );
+ LDAP_FREE( tag );
}
return( lfdp );
ldap_setfilteraffixes( LDAPFiltDesc *lfdp, LDAP_CONST char *prefix, LDAP_CONST char *suffix )
{
if ( lfdp->lfd_filtprefix != NULL ) {
- free( lfdp->lfd_filtprefix );
+ LDAP_FREE( lfdp->lfd_filtprefix );
}
lfdp->lfd_filtprefix = ( prefix == NULL ) ? NULL : strdup( prefix );
if ( lfdp->lfd_filtsuffix != NULL ) {
- free( lfdp->lfd_filtsuffix );
+ LDAP_FREE( lfdp->lfd_filtsuffix );
}
lfdp->lfd_filtsuffix = ( suffix == NULL ) ? NULL : strdup( suffix );
}
regex_t re;
if ( lfdp->lfd_curvalcopy != NULL ) {
- free( lfdp->lfd_curvalcopy );
- free( lfdp->lfd_curvalwords );
+ LDAP_FREE( lfdp->lfd_curvalcopy );
+ LDAP_FREE( lfdp->lfd_curvalwords );
}
lfdp->lfd_curval = value;
if ( break_into_words( lfdp->lfd_curvalcopy, flp->lfl_delims,
&lfdp->lfd_curvalwords ) < 0 ) {
- free( lfdp->lfd_curvalcopy );
+ LDAP_FREE( lfdp->lfd_curvalcopy );
lfdp->lfd_curvalcopy = NULL;
return( NULL );
}
int count;
char *tok_r;
- if (( words = (char **)calloc( 1, sizeof( char * ))) == NULL ) {
+ if (( words = (char **)LDAP_CALLOC( 1, sizeof( char * ))) == NULL ) {
return( -1 );
}
count = 0;
word = ldap_pvt_strtok( str, delims, &tok_r );
while ( word != NULL ) {
- if (( words = (char **)realloc( words,
+ if (( words = (char **)LDAP_REALLOC( words,
( count + 2 ) * sizeof( char * ))) == NULL ) {
return( -1 );
}
/* break out on success, return out on error */
while ( ! found ) {
- free(attr);
+ LDAP_FREE(attr);
attr = NULL;
if ( ber_scanf( &ber, "x}{a", &attr ) == LBER_ERROR ) {
}
- free(attr);
+ LDAP_FREE(attr);
attr = NULL;
/*
/* break out on success, return out on error */
while ( ! found ) {
- free( attr );
+ LDAP_FREE( attr );
attr = NULL;
if ( ber_scanf( &ber, "x}{a", &attr ) == LBER_ERROR ) {
break;
}
- free( attr );
+ LDAP_FREE( attr );
attr = NULL;
/*
if ( vals == NULL )
return;
for ( i = 0; vals[i] != NULL; i++ )
- free( vals[i] );
- free( (char *) vals );
+ LDAP_FREE( vals[i] );
+ LDAP_FREE( (char *) vals );
}
void
if ( vals == NULL )
return;
for ( i = 0; vals[i] != NULL; i++ ) {
- free( vals[i]->bv_val );
- free( vals[i] );
+ LDAP_FREE( vals[i]->bv_val );
+ LDAP_FREE( vals[i] );
}
- free( (char *) vals );
+ LDAP_FREE( (char *) vals );
}
case ATTR_STRING:
p = &((char *) &gopts)[attrs[i].offset];
- if (* (char**) p != NULL) free(* (char**) p);
+ if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
* (char**) p = strdup(opt);
break;
}
home = getenv("HOME");
if (home != NULL) {
- path = malloc(strlen(home) + strlen(file) + 3);
+ path = LDAP_MALLOC(strlen(home) + strlen(file) + 3);
} else {
- path = malloc(strlen(file) + 3);
+ path = LDAP_MALLOC(strlen(file) + 3);
}
if(home != NULL && path != NULL) {
}
if(path != NULL) {
- free(path);
+ LDAP_FREE(path);
}
/* try file */
case ATTR_STRING:
p = &((char *) &gopts)[attrs[i].offset];
- if (* (char**) p != NULL) free(* (char**) p);
+ if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
if (*value == '\0') {
* (char**) p = NULL;
} else {
/* create a message to send */
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
- free( cred );
+ LDAP_FREE( cred );
return( -1 );
}
#endif /* STR_TRANSLATION */
if ( rc == -1 ) {
- free( cred );
+ LDAP_FREE( cred );
ber_free( ber, 1 );
ld->ld_errno = LDAP_ENCODING_ERROR;
return( -1 );
}
- free( cred );
+ LDAP_FREE( cred );
#ifndef LDAP_NOCACHE
if ( ld->ld_cache != NULL ) {
/* create a message to send */
if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
- free( cred );
+ LDAP_FREE( cred );
return( -1 );
}
}
#endif /* STR_TRANSLATION */
- free( cred );
+ LDAP_FREE( cred );
if ( rc == -1 ) {
ber_free( ber, 1 );
return( NULL );
}
- if ( ( cred = malloc( ktxt.length )) == NULL ) {
+ if ( ( cred = LDAP_MALLOC( ktxt.length )) == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( NULL );
}
void ldap_int_initialize LDAP_P((void));
+/* memory.c */
+ /* simple macros to realloc for now */
+#define LDAP_MALLOC(s) (LBER_MALLOC((s)))
+#define LDAP_CALLOC(n,s) (LBER_CALLOC((n),(s)))
+#define LDAP_REALLOC(p,s) (LBER_REALLOC((p),(s)))
+#define LDAP_FREE(p) (LBER_FREE((p)))
+
/*
* in unit-int.c
*/
/*
* in strdup.c
*/
-char *ldap_strdup LDAP_P(( const char * ));
+char *ldap_pvt_strdup LDAP_P(( const char * ));
+#undef strdup
+#define strdup ldap_pvt_strdup
/*
* in unbind.c
return( NULL );
}
- if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer ))) ==
+ if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer ))) ==
NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host =
strdup( ld->ld_defhost )) == NULL )) {
- if(srv != NULL) free( (char*) srv );
+ if(srv != NULL) LDAP_FREE( (char*) srv );
ldap_ld_free( ld, 0, NULL, NULL );
return( NULL );
}
srv->lsrv_port = ld->ld_defport;
if (( ld->ld_defconn = ldap_new_connection( ld, &srv, 1,1,0 )) == NULL ) {
- if ( ld->ld_defhost != NULL ) free( srv->lsrv_host );
- free( (char *)srv );
+ if ( ld->ld_defhost != NULL ) LDAP_FREE( srv->lsrv_host );
+ LDAP_FREE( (char *)srv );
ldap_ld_free( ld, 0, NULL, NULL );
return( NULL );
}
}
#endif
- if ( (ld = (LDAP *) calloc( 1, sizeof(LDAP) )) == NULL ) {
+ if ( (ld = (LDAP *) LDAP_CALLOC( 1, sizeof(LDAP) )) == NULL ) {
WSACleanup( );
return( NULL );
}
}
if ( ld->ld_options.ldo_defhost == NULL ) {
- free( (char*)ld );
+ LDAP_FREE( (char*)ld );
WSACleanup( );
return( NULL );
}
}
if (( ld->ld_selectinfo = ldap_new_select_info()) == NULL ) {
- free( (char*) ld->ld_options.ldo_defhost );
+ LDAP_FREE( (char*) ld->ld_options.ldo_defhost );
if ( ld->ld_options.ldo_defbase == NULL ) {
- free( (char*) ld->ld_options.ldo_defbase );
+ LDAP_FREE( (char*) ld->ld_options.ldo_defbase );
}
- free( (char*) ld );
+ LDAP_FREE( (char*) ld );
WSACleanup( );
return( NULL );
}
info->ldapai_extensions = NULL;
} else {
int i;
- info->ldapai_extensions = malloc(sizeof(char *) *
+ info->ldapai_extensions = LDAP_MALLOC(sizeof(char *) *
sizeof(features)/sizeof(LDAPAPIFeatureInfo));
for(i=0; features[i].ldapaif_name != NULL; i++) {
char* host = (char *) invalue;
if(lo->ldo_defhost != NULL) {
- free(lo->ldo_defhost);
+ LDAP_FREE(lo->ldo_defhost);
lo->ldo_defhost = NULL;
}
}
if( ld->ld_error ) {
- free(ld->ld_error);
+ LDAP_FREE(ld->ld_error);
}
ld->ld_error = strdup(err);
struct hostent he_buf;
int local_h_errno;
char *ha_buf=NULL;
-#define DO_RETURN(x) if (ha_buf) free(ha_buf); return (x);
+#define DO_RETURN(x) if (ha_buf) LDAP_FREE(ha_buf); return (x);
Debug( LDAP_DEBUG_TRACE, "ldap_connect_to_host: %s:%d\n",
( host == NULL ) ? "(by address)" : host, (int) ntohs( (short) port ), 0 );
struct hostent he_buf;
int local_h_errno;
char *ha_buf=NULL;
-#define DO_RETURN(x) if (ha_buf) free(ha_buf); return (x);
+#define DO_RETURN(x) if (ha_buf) LDAP_FREE(ha_buf); return (x);
(void)memset( (char *)&sin, 0, sizeof( struct sockaddr_in ));
len = sizeof( sin );
{
struct selectinfo *sip;
- if (( sip = (struct selectinfo *)calloc( 1,
+ if (( sip = (struct selectinfo *)LDAP_CALLOC( 1,
sizeof( struct selectinfo ))) != NULL ) {
FD_ZERO( &sip->si_readfds );
FD_ZERO( &sip->si_writefds );
void
ldap_free_select_info( void *sip )
{
- free( sip );
+ LDAP_FREE( sip );
}
if( rc != LDAP_SUCCESS ) {
ld->ld_errno = rc;
- if( ld->ld_matched != NULL )
- free( ld->ld_matched );
-
- ld->ld_matched = NULL;
-
- if( ld->ld_error != NULL )
- free( ld->ld_error );
+ if( ld->ld_matched != NULL ) {
+ LDAP_FREE( ld->ld_matched );
+ ld->ld_matched = NULL;
+ }
- ld->ld_error = NULL;
+ if( ld->ld_error != NULL ) {
+ LDAP_FREE( ld->ld_error );
+ ld->ld_error = NULL;
+ }
}
return rc;
if ( ! ber_pvt_sb_in_use(&ld->ld_sb ) ) {
/* not connected yet */
- if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer ))) ==
+ if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer ))) ==
NULL || ( ld->ld_defhost != NULL && ( srv->lsrv_host =
strdup( ld->ld_defhost )) == NULL ))
{
- if (srv != NULL) free( srv );
+ if (srv != NULL) LDAP_FREE( srv );
ber_free( ber, 1 );
ld->ld_errno = LDAP_NO_MEMORY;
return( -1 );
if (( ld->ld_defconn = ldap_new_connection( ld, &srv, 1,1,0 ))
== NULL )
{
- if ( ld->ld_defhost != NULL ) free( srv->lsrv_host );
- free( (char *)srv );
+ if ( ld->ld_defhost != NULL ) LDAP_FREE( srv->lsrv_host );
+ LDAP_FREE( (char *)srv );
ber_free( ber, 1 );
ld->ld_errno = LDAP_SERVER_DOWN;
return( -1 );
}
use_connection( ld, lc );
- if (( lr = (LDAPRequest *)calloc( 1, sizeof( LDAPRequest ))) ==
+ if (( lr = (LDAPRequest *)LDAP_CALLOC( 1, sizeof( LDAPRequest ))) ==
NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
ldap_free_connection( ld, lc, 0, 0 );
* make a new LDAP server connection
* XXX open connection synchronously for now
*/
- if (( lc = (LDAPConn *)calloc( 1, sizeof( LDAPConn ))) == NULL ||
+ if (( lc = (LDAPConn *)LDAP_CALLOC( 1, sizeof( LDAPConn ))) == NULL ||
( !use_ldsb && ( (sb = ber_sockbuf_alloc()) == NULL ))) {
if ( lc != NULL ) {
- free( (char *)lc );
+ LDAP_FREE( (char *)lc );
}
ld->ld_errno = LDAP_NO_MEMORY;
return( NULL );
if ( !use_ldsb ) {
ber_sockbuf_free( lc->lconn_sb );
}
- free( (char *)lc );
+ LDAP_FREE( (char *)lc );
ld->ld_errno = LDAP_SERVER_DOWN;
return( NULL );
}
}
free_servers( lc->lconn_server );
if ( lc->lconn_krbinstance != NULL ) {
- free( lc->lconn_krbinstance );
+ LDAP_FREE( lc->lconn_krbinstance );
}
if ( lc->lconn_sb != &ld->ld_sb ) {
ber_sockbuf_free( lc->lconn_sb );
}
- free( lc );
+ LDAP_FREE( lc );
Debug( LDAP_DEBUG_TRACE, "ldap_free_connection: actually freed\n",
0, 0, 0 );
} else {
}
if ( lr->lr_res_error != NULL ) {
- free( lr->lr_res_error );
+ LDAP_FREE( lr->lr_res_error );
}
if ( lr->lr_res_matched != NULL ) {
- free( lr->lr_res_matched );
+ LDAP_FREE( lr->lr_res_matched );
}
- free( lr );
+ LDAP_FREE( lr );
}
while ( srvlist != NULL ) {
nextsrv = srvlist->lsrv_next;
if ( srvlist->lsrv_dn != NULL ) {
- free( srvlist->lsrv_dn );
+ LDAP_FREE( srvlist->lsrv_dn );
}
if ( srvlist->lsrv_host != NULL ) {
- free( srvlist->lsrv_host );
+ LDAP_FREE( srvlist->lsrv_host );
}
- free( srvlist );
+ LDAP_FREE( srvlist );
srvlist = nextsrv;
}
}
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
if ( ldapref ) {
#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */
- if (( srv = (LDAPServer *)calloc( 1,
+ if (( srv = (LDAPServer *)LDAP_CALLOC( 1,
sizeof( LDAPServer ))) == NULL ) {
ber_free( ber, 1 );
ld->ld_errno = LDAP_NO_MEMORY;
}
if (( srv->lsrv_host = strdup( tmpref )) == NULL ) {
- free( (char *)srv );
+ LDAP_FREE( (char *)srv );
ber_free( ber, 1 );
ld->ld_errno = LDAP_NO_MEMORY;
return( -1 );
}
if ( !newdn && refdn != NULL ) {
- free( refdn );
+ LDAP_FREE( refdn );
}
}
- free( *errstrp );
+ LDAP_FREE( *errstrp );
*errstrp = unfollowed;
return(( rc == 0 ) ? count : rc );
if ( *referralsp == NULL ) {
first = 1;
- *referralsp = (char *)malloc( strlen( s ) + LDAP_REF_STR_LEN
+ *referralsp = (char *)LDAP_MALLOC( strlen( s ) + LDAP_REF_STR_LEN
+ 1 );
} else {
first = 0;
- *referralsp = (char *)realloc( *referralsp,
+ *referralsp = (char *)LDAP_REALLOC( *referralsp,
strlen( *referralsp ) + strlen( s ) + 2 );
}
if ( *dnp == NULL ) {
*dnp = orig_dn;
} else {
- free( orig_dn );
+ LDAP_FREE( orig_dn );
}
if ( tag == LDAP_REQ_BIND ) {
}
if ( host != NULL ) { /* found a server we can use */
- if (( srv = (LDAPServer *)calloc( 1,
+ if (( srv = (LDAPServer *)LDAP_CALLOC( 1,
sizeof( LDAPServer ))) == NULL ) {
free_servers( srvlist );
srvlist = NULL;
}
/* make a new ldap message */
- if ( (new = (LDAPMessage *) calloc( 1, sizeof(LDAPMessage) ))
+ if ( (new = (LDAPMessage *) LDAP_CALLOC( 1, sizeof(LDAPMessage) ))
== NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( -1 );
parentr->lr_res_errno == LDAP_SUCCESS ) {
parentr->lr_res_errno = lr->lr_res_errno;
if ( parentr->lr_res_error != NULL ) {
- free( parentr->lr_res_error );
+ LDAP_FREE( parentr->lr_res_error );
}
parentr->lr_res_error = lr->lr_res_error;
lr->lr_res_error = NULL;
if ( LDAP_NAME_ERROR( lr->lr_res_errno )) {
if ( parentr->lr_res_matched != NULL ) {
- free( parentr->lr_res_matched );
+ LDAP_FREE( parentr->lr_res_matched );
}
parentr->lr_res_matched = lr->lr_res_matched;
lr->lr_res_matched = NULL;
next = lm->lm_chain;
type = lm->lm_msgtype;
ber_free( lm->lm_ber, 1 );
- free( (char *) lm );
+ LDAP_FREE( (char *) lm );
}
return( type );
#include <ac/ctype.h>
#include <ac/string.h>
+#include <ac/time.h>
+
+#include "ldap-int.h"
-#include <lber.h>
-#include <ldap.h>
#include <ldap_schema.h>
/*
{
safe_string * ss;
- ss = malloc(sizeof(safe_string));
+ ss = LDAP_MALLOC(sizeof(safe_string));
if ( !ss )
return(NULL);
ss->size = size;
ss->pos = 0;
- ss->val = malloc(size);
+ ss->val = LDAP_MALLOC(size);
ss->at_whsp = 0;
if ( !ss->val ) {
- free(ss);
+ LDAP_FREE(ss);
return(NULL);
}
return ss;
/* We always make sure there is at least one position available */
if ( ss->pos + l >= ss->size-1 ) {
ss->size *= 2;
- temp = realloc(ss->val, ss->size);
+ temp = LDAP_REALLOC(ss->val, ss->size);
if ( !temp ) {
/* Trouble, out of memory */
- free(ss->val);
+ LDAP_FREE(ss->val);
return -1;
}
ss->val = temp;
for ( a = array; *a != NULL; a++ ) {
if ( *a != NULL ) {
- free( *a );
+ LDAP_FREE( *a );
}
}
- free( (char *) array );
+ LDAP_FREE( (char *) array );
}
/*
(*sp)++;
if ( **sp == '\'' ) {
q = *sp;
- res = malloc(q-p+1);
+ res = LDAP_MALLOC(q-p+1);
if ( !res ) {
kind = TK_OUTOFMEM;
} else {
while ( !isspace(**sp) && **sp != '\0' )
(*sp)++;
q = *sp;
- res = malloc(q-p+1);
+ res = LDAP_MALLOC(q-p+1);
if ( !res ) {
kind = TK_OUTOFMEM;
} else {
}
/* At this point, *sp points at the char past the numericoid. Perfect. */
len = *sp - start;
- res = malloc(len+1);
+ res = LDAP_MALLOC(len+1);
if (!res) {
*code = LDAP_SCHERR_OUTOFMEM;
return(NULL);
if ( kind == TK_LEFTPAREN ) {
/* Let's presume there will be at least 2 entries */
size = 3;
- res = calloc(3,sizeof(char *));
+ res = LDAP_CALLOC(3,sizeof(char *));
if ( !res ) {
*code = LDAP_SCHERR_OUTOFMEM;
return NULL;
if ( kind == TK_QDESCR ) {
if ( pos == size-2 ) {
size++;
- res1 = realloc(res,size*sizeof(char *));
+ res1 = LDAP_REALLOC(res,size*sizeof(char *));
if ( !res1 ) {
charray_free(res);
*code = LDAP_SCHERR_OUTOFMEM;
parse_whsp(sp);
return(res);
} else if ( kind == TK_QDESCR ) {
- res = calloc(2,sizeof(char *));
+ res = LDAP_CALLOC(2,sizeof(char *));
if ( !res ) {
*code = LDAP_SCHERR_OUTOFMEM;
return NULL;
if ( kind == TK_LEFTPAREN ) {
/* Let's presume there will be at least 2 entries */
size = 3;
- res = calloc(3,sizeof(char *));
+ res = LDAP_CALLOC(3,sizeof(char *));
if ( !res ) {
*code = LDAP_SCHERR_OUTOFMEM;
return NULL;
if ( kind == TK_BAREWORD ) {
if ( pos == size-2 ) {
size++;
- res1 = realloc(res,size*sizeof(char *));
+ res1 = LDAP_REALLOC(res,size*sizeof(char *));
if ( !res1 ) {
charray_free(res);
*code = LDAP_SCHERR_OUTOFMEM;
parse_whsp(sp);
return(res);
} else if ( kind == TK_BAREWORD ) {
- res = calloc(2,sizeof(char *));
+ res = LDAP_CALLOC(2,sizeof(char *));
if ( !res ) {
*code = LDAP_SCHERR_OUTOFMEM;
return NULL;
LDAP_ATTRIBUTE_TYPE * at;
*errp = s;
- at = calloc(1,sizeof(LDAP_ATTRIBUTE_TYPE));
+ at = LDAP_CALLOC(1,sizeof(LDAP_ATTRIBUTE_TYPE));
if ( !at ) {
*code = LDAP_SCHERR_OUTOFMEM;
LDAP_OBJECT_CLASS * oc;
*errp = s;
- oc = calloc(1,sizeof(LDAP_OBJECT_CLASS));
+ oc = LDAP_CALLOC(1,sizeof(LDAP_OBJECT_CLASS));
if ( !oc ) {
*code = LDAP_SCHERR_OUTOFMEM;
filter = strdup( filter_in );
err = put_filter( ber, filter );
- free( filter );
+ LDAP_FREE( filter );
if ( err == -1 ) {
ld->ld_errno = LDAP_FILTER_ERROR;
*d = '\0';
}
if ( put_simple_filter( ber, tmp ) == -1 ) {
- free( tmp );
+ LDAP_FREE( tmp );
return( -1 );
}
- free( tmp );
+ LDAP_FREE( tmp );
*next++ = ')';
str = next;
parens--;
*d = '\0';
}
if ( put_simple_filter( ber, tmp ) == -1 ) {
- free( tmp );
+ LDAP_FREE( tmp );
return( -1 );
}
- free( tmp );
+ LDAP_FREE( tmp );
str = next;
break;
}
return 0;
}
- if ( (et = (struct entrything *) malloc( count *
+ if ( (et = (struct entrything *) LDAP_MALLOC( count *
sizeof(struct entrything) )) == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( -1 );
dn = ldap_get_dn( ld, e );
et[i].et_vals = ldap_explode_dn( dn, 1 );
- free( dn );
+ LDAP_FREE( dn );
} else {
et[i].et_vals = ldap_get_values( ld, e, attr );
}
ldap_value_free( et[i].et_vals );
}
*ep = last;
- free( (char *) et );
+ LDAP_FREE( (char *) et );
return( 0 );
}
return( LDAP_SEARCHPREF_ERR_FILE );
}
- if (( buf = malloc( (size_t)len )) == NULL ) {
+ if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) {
fclose( fp );
return( LDAP_SEARCHPREF_ERR_MEM );
}
fclose( fp );
if ( rlen != len && !eof ) { /* error: didn't get the whole file */
- free( buf );
+ LDAP_FREE( buf );
return( LDAP_SEARCHPREF_ERR_FILE );
}
rc = ldap_init_searchprefs_buf( buf, rlen, solistp );
- free( buf );
+ LDAP_FREE( buf );
return( rc );
}
{
if ( so != NULL ) {
if ( so->so_objtypeprompt != NULL ) {
- free( so->so_objtypeprompt );
+ LDAP_FREE( so->so_objtypeprompt );
}
if ( so->so_prompt != NULL ) {
- free( so->so_prompt );
+ LDAP_FREE( so->so_prompt );
}
if ( so->so_filterprefix != NULL ) {
- free( so->so_filterprefix );
+ LDAP_FREE( so->so_filterprefix );
}
if ( so->so_filtertag != NULL ) {
- free( so->so_filtertag );
+ LDAP_FREE( so->so_filtertag );
}
if ( so->so_defaultselectattr != NULL ) {
- free( so->so_defaultselectattr );
+ LDAP_FREE( so->so_defaultselectattr );
}
if ( so->so_defaultselecttext != NULL ) {
- free( so->so_defaultselecttext );
+ LDAP_FREE( so->so_defaultselecttext );
}
if ( so->so_salist != NULL ) {
struct ldap_searchattr *sa, *nextsa;
for ( sa = so->so_salist; sa != NULL; sa = nextsa ) {
nextsa = sa->sa_next;
if ( sa->sa_attrlabel != NULL ) {
- free( sa->sa_attrlabel );
+ LDAP_FREE( sa->sa_attrlabel );
}
if ( sa->sa_attr != NULL ) {
- free( sa->sa_attr );
+ LDAP_FREE( sa->sa_attr );
}
if ( sa->sa_selectattr != NULL ) {
- free( sa->sa_selectattr );
+ LDAP_FREE( sa->sa_selectattr );
}
if ( sa->sa_selecttext != NULL ) {
- free( sa->sa_selecttext );
+ LDAP_FREE( sa->sa_selecttext );
}
- free( sa );
+ LDAP_FREE( sa );
}
}
if ( so->so_smlist != NULL ) {
for ( sm = so->so_smlist; sm != NULL; sm = nextsm ) {
nextsm = sm->sm_next;
if ( sm->sm_matchprompt != NULL ) {
- free( sm->sm_matchprompt );
+ LDAP_FREE( sm->sm_matchprompt );
}
if ( sm->sm_filter != NULL ) {
- free( sm->sm_filter );
+ LDAP_FREE( sm->sm_filter );
}
- free( sm );
+ LDAP_FREE( sm );
}
}
- free( so );
+ LDAP_FREE( so );
}
}
return( tokcnt == 0 ? 0 : LDAP_SEARCHPREF_ERR_SYNTAX );
}
- if (( so = (struct ldap_searchobj *)calloc( 1,
+ if (( so = (struct ldap_searchobj *)LDAP_CALLOC( 1,
sizeof( struct ldap_searchobj ))) == NULL ) {
free_strarray( toks );
return( LDAP_SEARCHPREF_ERR_MEM );
}
so->so_objtypeprompt = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* if this is post-version zero, options come next
return( LDAP_SEARCHPREF_ERR_SYNTAX );
}
so->so_prompt = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* Filter prefix for "More Choices" searching is next
return( LDAP_SEARCHPREF_ERR_SYNTAX );
}
so->so_filterprefix = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* "Fewer Choices" filter tag comes next
return( LDAP_SEARCHPREF_ERR_SYNTAX );
}
so->so_filtertag = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* Selection (disambiguation) attribute comes next
return( LDAP_SEARCHPREF_ERR_SYNTAX );
}
so->so_defaultselectattr = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* Label for selection (disambiguation) attribute
return( LDAP_SEARCHPREF_ERR_SYNTAX );
}
so->so_defaultselecttext = toks[ 0 ];
- free( (char *)toks );
+ LDAP_FREE( (char *)toks );
/*
* Search scope is next
ldap_free_searchprefs( so );
return( LDAP_SEARCHPREF_ERR_SYNTAX );
}
- if (( *sa = ( struct ldap_searchattr * ) calloc( 1,
+ if (( *sa = ( struct ldap_searchattr * ) LDAP_CALLOC( 1,
sizeof( struct ldap_searchattr ))) == NULL ) {
free_strarray( toks );
ldap_free_searchprefs( so );
( *sa )->sa_matchtypebitmap |= (1 << j);
}
}
- free( toks[ 2 ] );
- free( ( char * ) toks );
+ LDAP_FREE( toks[ 2 ] );
+ LDAP_FREE( ( char * ) toks );
sa = &(( *sa )->sa_next);
}
*sa = NULL;
ldap_free_searchprefs( so );
return( LDAP_SEARCHPREF_ERR_SYNTAX );
}
- if (( *sm = ( struct ldap_searchmatch * ) calloc( 1,
+ if (( *sm = ( struct ldap_searchmatch * ) LDAP_CALLOC( 1,
sizeof( struct ldap_searchmatch ))) == NULL ) {
free_strarray( toks );
ldap_free_searchprefs( so );
}
( *sm )->sm_matchprompt = toks[ 0 ];
( *sm )->sm_filter = toks[ 1 ];
- free( ( char * ) toks );
+ LDAP_FREE( ( char * ) toks );
sm = &(( *sm )->sm_next );
}
*sm = NULL;
char *p;
size_t len = strlen( s ) + 1;
- if ( (p = (char *) malloc( len )) == NULL ) {
+ if ( (p = (char *) LDAP_MALLOC( len )) == NULL ) {
return( NULL );
}
}
if ( buf == NULL ) {
- if (( buf = malloc( LDAP_DTMPL_BUFSIZ )) == NULL ) {
+ if (( buf = LDAP_MALLOC( LDAP_DTMPL_BUFSIZ )) == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
- free( dn );
+ LDAP_FREE( dn );
return( ld->ld_errno );
}
freebuf = 1;
(*writeproc)( writeparm, buf, strlen( buf ));
}
- free( dn );
+ LDAP_FREE( dn );
if ( freebuf ) {
- free( buf );
+ LDAP_FREE( buf );
}
return( err );
timeout.tv_sec = SEARCH_TIMEOUT_SECS;
timeout.tv_usec = 0;
- if (( buf = malloc( LDAP_DTMPL_BUFSIZ )) == NULL ) {
+ if (( buf = LDAP_MALLOC( LDAP_DTMPL_BUFSIZ )) == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( ld->ld_errno );
}
if ( dn == NULL ) {
if (( dn = ldap_get_dn( ld, entry )) == NULL ) {
- free( buf );
+ LDAP_FREE( buf );
if ( freetmpls ) {
ldap_free_templates( tmpllist );
}
fetchattrs, 0, &timeout, &ldmp );
if ( freedn ) {
- free( dn );
+ LDAP_FREE( dn );
}
if ( fetchattrs != NULL ) {
ldap_value_free( fetchattrs );
if ( freetmpls ) {
ldap_free_templates( tmpllist );
}
- free( buf );
+ LDAP_FREE( buf );
return( ld->ld_errno );
}
err = do_entry2text( ld, buf, base, entry, tmpl, defattrs, defvals,
writeproc, writeparm, eol, rdncount, opts, urlprefix );
- free( buf );
+ LDAP_FREE( buf );
if ( freetmpls ) {
ldap_free_templates( tmpllist );
}
}
if ( buf == NULL ) {
- if (( buf = malloc( LDAP_DTMPL_BUFSIZ )) == NULL ) {
+ if (( buf = LDAP_MALLOC( LDAP_DTMPL_BUFSIZ )) == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( ld->ld_errno );
}
}
if ( freebuf ) {
- free( buf );
+ LDAP_FREE( buf );
}
return( LDAP_SUCCESS );
if ( lderr == LDAP_SUCCESS || NONFATAL_LDAP_ERR( lderr )) {
if (( count = ldap_count_entries( ld, ldmp )) > 0 ) {
- if (( members = (char **)malloc( (count + 1) * sizeof(char *)))
+ if (( members = (char **)LDAP_MALLOC( (count + 1) * sizeof(char *)))
== NULL ) {
err = LDAP_NO_MEMORY;
} else {
if ( candidates == NULL ) {
if ( prefix != NULL ) {
- if ( (dns = (char **) malloc( sizeof(char *)
+ if ( (dns = (char **) LDAP_MALLOC( sizeof(char *)
* 2 )) == NULL ) {
return( ld->ld_errno = LDAP_NO_MEMORY );
}
continue;
if ( dns == NULL ) {
- if ( (dns = (char **) malloc(
+ if ( (dns = (char **) LDAP_MALLOC(
sizeof(char *) * 8 )) == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( LDAP_NO_MEMORY );
}
max = 8;
} else if ( i >= max ) {
- if ( (dns = (char **) realloc( dns,
+ if ( (dns = (char **) LDAP_REALLOC( dns,
sizeof(char *) * 2 * max ))
== NULL )
{
}
for ( pcomp = 0; prefixcomp[pcomp] != NULL; pcomp++ )
; /* NULL */
- if ( (pbuf = (char *) malloc( strlen( ld->ld_ufnprefix ) + 1 ))
+ if ( (pbuf = (char *) LDAP_MALLOC( strlen( ld->ld_ufnprefix ) + 1 ))
== NULL ) {
ldap_value_free( ufncomp );
ldap_value_free( prefixcomp );
ldap_value_free( ufncomp );
ldap_value_free( prefixcomp );
- free( pbuf );
+ LDAP_FREE( pbuf );
return( err );
}
ldap_ufn_setprefix( LDAP *ld, LDAP_CONST char *prefix )
{
if ( ld->ld_ufnprefix != NULL )
- free( ld->ld_ufnprefix );
+ LDAP_FREE( ld->ld_ufnprefix );
ld->ld_ufnprefix = strdup( prefix );
}
int i;
for ( i = 0; i < ld->ld_cldapnaddr; ++i ) {
- free( ld->ld_cldapaddrs[ i ] );
+ LDAP_FREE( ld->ld_cldapaddrs[ i ] );
}
- free( ld->ld_cldapaddrs );
+ LDAP_FREE( ld->ld_cldapaddrs );
}
for ( lm = ld->ld_responses; lm != NULL; lm = next ) {
#endif /* !LDAP_NOCACHE */
if ( ld->ld_error != NULL ) {
- free( ld->ld_error );
+ LDAP_FREE( ld->ld_error );
ld->ld_error = NULL;
}
if ( ld->ld_matched != NULL ) {
- free( ld->ld_matched );
+ LDAP_FREE( ld->ld_matched );
ld->ld_matched = NULL;
}
if ( ld->ld_host != NULL ) {
- free( ld->ld_host );
+ LDAP_FREE( ld->ld_host );
ld->ld_host = NULL;
}
if ( ld->ld_ufnprefix != NULL ) {
- free( ld->ld_ufnprefix );
+ LDAP_FREE( ld->ld_ufnprefix );
ld->ld_ufnprefix = NULL;
}
}
if ( ld->ld_abandoned != NULL ) {
- free( ld->ld_abandoned );
+ LDAP_FREE( ld->ld_abandoned );
ld->ld_abandoned = NULL;
}
}
if ( ld->ld_options.ldo_defbase != NULL ) {
- free( ld->ld_options.ldo_defbase );
+ LDAP_FREE( ld->ld_options.ldo_defbase );
ld->ld_options.ldo_defbase = NULL;
}
if ( ld->ld_options.ldo_defhost != NULL ) {
- free( ld->ld_options.ldo_defhost );
+ LDAP_FREE( ld->ld_options.ldo_defhost );
ld->ld_options.ldo_defhost = NULL;
}
ber_pvt_sb_destroy( &(ld->ld_sb) );
- free( (char *) ld );
+ LDAP_FREE( (char *) ld );
WSACleanup();
}
/* allocate return struct */
- if (( ludp = (LDAPURLDesc *)calloc( 1, sizeof( LDAPURLDesc )))
+ if (( ludp = (LDAPURLDesc *)LDAP_CALLOC( 1, sizeof( LDAPURLDesc )))
== NULLLDAPURLDESC )
{
- free( url );
+ LDAP_FREE( url );
return( LDAP_URL_ERR_MEM );
}
}
}
- if (( ludp->lud_attrs = (char **)calloc( nattrs + 1,
+ if (( ludp->lud_attrs = (char **)LDAP_CALLOC( nattrs + 1,
sizeof( char * ))) == NULL ) {
ldap_free_urldesc( ludp );
return( LDAP_URL_ERR_MEM );
{
if ( ludp != NULLLDAPURLDESC ) {
if ( ludp->lud_string != NULL ) {
- free( ludp->lud_string );
+ LDAP_FREE( ludp->lud_string );
}
if ( ludp->lud_attrs != NULL ) {
- free( ludp->lud_attrs );
+ LDAP_FREE( ludp->lud_attrs );
}
- free( ludp );
+ LDAP_FREE( ludp );
}
}
err = 0;
if ( ludp->lud_host != NULL || ludp->lud_port != 0 ) {
- if (( srv = (LDAPServer *)calloc( 1, sizeof( LDAPServer )))
+ if (( srv = (LDAPServer *)LDAP_CALLOC( 1, sizeof( LDAPServer )))
== NULL || ( srv->lsrv_host = strdup( ludp->lud_host ==
NULL ? ld->ld_defhost : ludp->lud_host )) == NULL ) {
if ( srv != NULL ) {
- free( srv );
+ LDAP_FREE( srv );
}
ld->ld_errno = LDAP_NO_MEMORY;
err = -1;
static char *safe_realloc( char **buf, int len )
{
char *tmpbuf;
- tmpbuf = realloc( *buf, len );
+ tmpbuf = LDAP_REALLOC( *buf, len );
if (tmpbuf) {
*buf=tmpbuf;
}
# End Source File
# Begin Source File
+SOURCE=..\libldap\schema.c
+# End Source File
+# Begin Source File
+
SOURCE=..\libldap\search.c
# End Source File
# Begin Source File
}
-#define safe_realloc( ptr, size ) ( (ptr) == NULL ? malloc( size ) : \
- realloc( ptr, size ))
-
-
static void
addmodifyop( LDAPMod ***pmodsp, int modop, char *attr, char *value, int vlen )
{
}
if ( pmods == NULL || pmods[ i ] == NULL ) {
- if (( pmods = (LDAPMod **)safe_realloc( pmods, (i + 2) *
+ if (( pmods = (LDAPMod **)realloc( pmods, (i + 2) *
sizeof( LDAPMod * ))) == NULL ) {
- perror( "safe_realloc" );
+ perror( "realloc" );
exit( 1 );
}
*pmodsp = pmods;
}
}
if (( pmods[ i ]->mod_bvalues =
- (struct berval **)safe_realloc( pmods[ i ]->mod_bvalues,
+ (struct berval **)ber_realloc( pmods[ i ]->mod_bvalues,
(j + 2) * sizeof( struct berval * ))) == NULL ) {
- perror( "safe_realloc" );
+ perror( "ber_realloc" );
exit( 1 );
}
pmods[ i ]->mod_bvalues[ j + 1 ] = NULL;
- if (( bvp = (struct berval *)malloc( sizeof( struct berval )))
+ if (( bvp = (struct berval *)ber_malloc( sizeof( struct berval )))
== NULL ) {
perror( "malloc" );
exit( 1 );