17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
37c478bd9Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
47c478bd9Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
57c478bd9Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
87c478bd9Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
97c478bd9Sstevel@tonic-gate  * implied. See the License for the specific language governing
107c478bd9Sstevel@tonic-gate  * rights and limitations under the License.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
137c478bd9Sstevel@tonic-gate  * March 31, 1998.
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
167c478bd9Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
177c478bd9Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
187c478bd9Sstevel@tonic-gate  * Rights Reserved.
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * Contributor(s):
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *  Copyright (c) 1994 The Regents of the University of Michigan.
247c478bd9Sstevel@tonic-gate  *  All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  *  free.c - some free routines are included here to avoid having to
287c478bd9Sstevel@tonic-gate  *           link in lots of extra code when not using certain features
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #if 0
32*1da57d55SToomas Soome #ifndef lint
337c478bd9Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1994 The Regents of the University of Michigan.\nAll rights reserved.\n";
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include "ldap-int.h"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate void
407c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_getfilter_free(LDAPFiltDesc * lfdp)417c478bd9Sstevel@tonic-gate ldap_getfilter_free( LDAPFiltDesc *lfdp )
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate     LDAPFiltList	*flp, *nextflp;
447c478bd9Sstevel@tonic-gate     LDAPFiltInfo	*fip, *nextfip;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate     if ( lfdp == NULL ) {
477c478bd9Sstevel@tonic-gate 	return;
487c478bd9Sstevel@tonic-gate     }
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
517c478bd9Sstevel@tonic-gate 	for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
527c478bd9Sstevel@tonic-gate 	    nextfip = fip->lfi_next;
537c478bd9Sstevel@tonic-gate 	    NSLDAPI_FREE( fip->lfi_filter );
547c478bd9Sstevel@tonic-gate 	    NSLDAPI_FREE( fip->lfi_desc );
557c478bd9Sstevel@tonic-gate 	    NSLDAPI_FREE( fip );
567c478bd9Sstevel@tonic-gate 	}
577c478bd9Sstevel@tonic-gate 	nextflp = flp->lfl_next;
587c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( flp->lfl_pattern );
597c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( flp->lfl_delims );
607c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( flp->lfl_tag );
617c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( flp );
627c478bd9Sstevel@tonic-gate     }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate     if ( lfdp->lfd_curvalcopy != NULL ) {
657c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( lfdp->lfd_curvalcopy );
667c478bd9Sstevel@tonic-gate     }
677c478bd9Sstevel@tonic-gate     if ( lfdp->lfd_curvalwords != NULL ) {
687c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( lfdp->lfd_curvalwords );
697c478bd9Sstevel@tonic-gate     }
707c478bd9Sstevel@tonic-gate     if ( lfdp->lfd_filtprefix != NULL ) {
717c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( lfdp->lfd_filtprefix );
727c478bd9Sstevel@tonic-gate     }
737c478bd9Sstevel@tonic-gate     if ( lfdp->lfd_filtsuffix != NULL ) {
747c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( lfdp->lfd_filtsuffix );
757c478bd9Sstevel@tonic-gate     }
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate     NSLDAPI_FREE( lfdp );
787c478bd9Sstevel@tonic-gate }
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate  * free a null-terminated array of pointers to mod structures. the
837c478bd9Sstevel@tonic-gate  * structures are freed, not the array itself, unless the freemods
847c478bd9Sstevel@tonic-gate  * flag is set.
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate void
877c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_mods_free(LDAPMod ** mods,int freemods)887c478bd9Sstevel@tonic-gate ldap_mods_free( LDAPMod **mods, int freemods )
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate 	int	i;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAPMOD_ARRAY( mods )) {
937c478bd9Sstevel@tonic-gate 		return;
947c478bd9Sstevel@tonic-gate 	}
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	for ( i = 0; mods[i] != NULL; i++ ) {
977c478bd9Sstevel@tonic-gate 		if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
987c478bd9Sstevel@tonic-gate 			if ( mods[i]->mod_bvalues != NULL ) {
997c478bd9Sstevel@tonic-gate 				ber_bvecfree( mods[i]->mod_bvalues );
1007c478bd9Sstevel@tonic-gate 			}
1017c478bd9Sstevel@tonic-gate 		} else if ( mods[i]->mod_values != NULL ) {
1027c478bd9Sstevel@tonic-gate 			ldap_value_free( mods[i]->mod_values );
1037c478bd9Sstevel@tonic-gate 		}
1047c478bd9Sstevel@tonic-gate 		if ( mods[i]->mod_type != NULL ) {
1057c478bd9Sstevel@tonic-gate 			NSLDAPI_FREE( mods[i]->mod_type );
1067c478bd9Sstevel@tonic-gate 		}
1077c478bd9Sstevel@tonic-gate 		NSLDAPI_FREE( (char *) mods[i] );
1087c478bd9Sstevel@tonic-gate 	}
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	if ( freemods )
1117c478bd9Sstevel@tonic-gate 		NSLDAPI_FREE( (char *) mods );
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * ldap_memfree() is needed to ensure that memory allocated by the C runtime
1177c478bd9Sstevel@tonic-gate  * assocated with libldap is freed by the same runtime code.
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate void
1207c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_memfree(void * s)1217c478bd9Sstevel@tonic-gate ldap_memfree( void *s )
1227c478bd9Sstevel@tonic-gate {
1237c478bd9Sstevel@tonic-gate 	if ( s != NULL ) {
1247c478bd9Sstevel@tonic-gate 		NSLDAPI_FREE( s );
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * ldap_ber_free() is just a cover for ber_free()
1317c478bd9Sstevel@tonic-gate  * ber_free() checks for ber == NULL, so we don't bother.
1327c478bd9Sstevel@tonic-gate  */
1337c478bd9Sstevel@tonic-gate void
1347c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_ber_free(BerElement * ber,int freebuf)1357c478bd9Sstevel@tonic-gate ldap_ber_free( BerElement *ber, int freebuf )
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate 	ber_free( ber, freebuf );
1387c478bd9Sstevel@tonic-gate }
139