xref: /onnv-gate/usr/src/lib/libldap4/common/free.c (revision 3857:21b9b714e4ab)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  *
3*3857Sstevel  * Portions Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
4*3857Sstevel  * Use is subject to license terms.
50Sstevel@tonic-gate  *
60Sstevel@tonic-gate  */
70Sstevel@tonic-gate 
80Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
90Sstevel@tonic-gate 
100Sstevel@tonic-gate /*
110Sstevel@tonic-gate  *  Copyright (c) 1994 The Regents of the University of Michigan.
120Sstevel@tonic-gate  *  All rights reserved.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  *  free.c - some free routines are included here to avoid having to
150Sstevel@tonic-gate  *           link in lots of extra code when not using certain features
160Sstevel@tonic-gate  */
170Sstevel@tonic-gate 
180Sstevel@tonic-gate #ifndef lint
190Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1994 The Regents of the University of Michigan.\nAll rights reserved.\n";
200Sstevel@tonic-gate #endif
210Sstevel@tonic-gate 
220Sstevel@tonic-gate 
230Sstevel@tonic-gate #include <stdio.h>
240Sstevel@tonic-gate #include <string.h>
250Sstevel@tonic-gate #include <ctype.h>
260Sstevel@tonic-gate #ifdef MACOS
270Sstevel@tonic-gate #include <stdlib.h>
280Sstevel@tonic-gate #include "macos.h"
290Sstevel@tonic-gate #else /* MACOS */
300Sstevel@tonic-gate #ifdef DOS
310Sstevel@tonic-gate #include <malloc.h>
320Sstevel@tonic-gate #include "msdos.h"
330Sstevel@tonic-gate #else /* DOS */
340Sstevel@tonic-gate #include <sys/types.h>
350Sstevel@tonic-gate #include <stdlib.h>
360Sstevel@tonic-gate #endif /* DOS */
370Sstevel@tonic-gate #endif /* MACOS */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include "lber.h"
400Sstevel@tonic-gate #include "ldap.h"
410Sstevel@tonic-gate #include "ldap-private.h"
420Sstevel@tonic-gate 
430Sstevel@tonic-gate void
ldap_getfilter_free(LDAPFiltDesc * lfdp)440Sstevel@tonic-gate ldap_getfilter_free( LDAPFiltDesc *lfdp )
450Sstevel@tonic-gate {
460Sstevel@tonic-gate     LDAPFiltList	*flp, *nextflp;
470Sstevel@tonic-gate     LDAPFiltInfo	*fip, *nextfip;
480Sstevel@tonic-gate 
490Sstevel@tonic-gate     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
500Sstevel@tonic-gate 	for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
510Sstevel@tonic-gate 	    nextfip = fip->lfi_next;
520Sstevel@tonic-gate 	    free( fip->lfi_filter );
530Sstevel@tonic-gate 	    free( fip->lfi_desc );
540Sstevel@tonic-gate 	    free( fip );
550Sstevel@tonic-gate 	}
560Sstevel@tonic-gate 	nextflp = flp->lfl_next;
570Sstevel@tonic-gate 	free( flp->lfl_pattern );
580Sstevel@tonic-gate 	free( flp->lfl_delims );
590Sstevel@tonic-gate 	free( flp->lfl_tag );
600Sstevel@tonic-gate 	free( flp );
610Sstevel@tonic-gate     }
620Sstevel@tonic-gate 
630Sstevel@tonic-gate     if ( lfdp->lfd_curvalcopy != NULL ) {
640Sstevel@tonic-gate 	free( lfdp->lfd_curvalcopy );
650Sstevel@tonic-gate     }
660Sstevel@tonic-gate     if ( lfdp->lfd_curvalwords != NULL ) {
670Sstevel@tonic-gate 	free( lfdp->lfd_curvalwords );
680Sstevel@tonic-gate     }
690Sstevel@tonic-gate     if ( lfdp->lfd_filtprefix != NULL ) {
700Sstevel@tonic-gate 	free( lfdp->lfd_filtprefix );
710Sstevel@tonic-gate     }
720Sstevel@tonic-gate     if ( lfdp->lfd_filtsuffix != NULL ) {
730Sstevel@tonic-gate 	free( lfdp->lfd_filtsuffix );
740Sstevel@tonic-gate     }
750Sstevel@tonic-gate 
760Sstevel@tonic-gate     free( lfdp );
770Sstevel@tonic-gate }
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate  * free a null-terminated array of pointers to mod structures. the
810Sstevel@tonic-gate  * structures are freed, not the array itself, unless the freemods
820Sstevel@tonic-gate  * flag is set.
830Sstevel@tonic-gate  */
840Sstevel@tonic-gate 
850Sstevel@tonic-gate void
ldap_mods_free(LDAPMod ** mods,int freemods)860Sstevel@tonic-gate ldap_mods_free( LDAPMod **mods, int freemods )
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 	int	i;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	if ( mods == NULL )
910Sstevel@tonic-gate 		return;
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	for ( i = 0; mods[i] != NULL; i++ ) {
940Sstevel@tonic-gate 		if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
950Sstevel@tonic-gate 			ber_bvecfree( mods[i]->mod_bvalues );
960Sstevel@tonic-gate 		} else {
970Sstevel@tonic-gate 			ldap_value_free( mods[i]->mod_values );
980Sstevel@tonic-gate 		}
990Sstevel@tonic-gate 		if (mods[i]->mod_type)
1000Sstevel@tonic-gate 			free(mods[i]->mod_type);
1010Sstevel@tonic-gate 		free( (char *) mods[i] );
1020Sstevel@tonic-gate 	}
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	if ( freemods )
1050Sstevel@tonic-gate 		free( (char *) mods );
1060Sstevel@tonic-gate }
107