ldap_mods_free() function frees the LDAPMod structures that you've allocated to add or modify entries. You need to call this function only if you've allocated memory for these structures yourself.
#include <ldap.h>
void ldap_mods_free( LDAPMod **mods, int freemods );
mods |
Pointer to a NULL-terminated array of pointers to |
freemods |
If this is a non-zero value, frees the array of pointers as well as the |
LDAPMod structures and frees them when done.
#include <stdio.h>
#include <ldap.h>
...
LDAP *ld;
char *dn;
int i, msgid;
LDAPMod **mods;
...
/* Construct the array of values to add */
mods = ( LDAPMod ** ) malloc(( NMODS + 1 ) * sizeof( LDAPMod * ));
if ( mods == NULL ) { fprintf( stderr, "Cannot allocate memory for mods array\n" );
}
for ( i = 0; i < NMODS; i++ ) { if (( mods[ i ] = ( LDAPMod * ) malloc( sizeof( LDAPMod ))) == NULL) {fprintf( stderr, "Cannot allocate memory for mods element\n" );
exit( 1 );
}
}
...
/* Code for filling the structures goes here. */
...
/* Initiate the add operation */
if (( msgid = ldap_add( ld, dn, mods )) < 0 ) { ldap_perror( ld, "ldap_add" );
ldap_mods_free( mods, 1 );
return( 1 );
}
...
Last Updated: 10/01/98 17:06:23