Table of Contents | Previous | Next | Index

Netscape Directory SDK 3.0 for C Programmer’s Guide
     Chapter 18 Functions

ldap_mods_free()

The 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.

Syntax

#include <ldap.h>
void ldap_mods_free( LDAPMod **mods, int freemods );

Parameters

This function has the following parameters:

mods

Pointer to a NULL-terminated array of pointers to LDAPMod structures.

freemods

If this is a non-zero value, frees the array of pointers as well as the LDAPMod structures. If 0, just frees the LDAPMod structures.

Example

The following example allocates memory for 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 ); 
}
...

Table of Contents | Previous | Next | Index

Last Updated: 10/01/98 17:06:23