xref: /titanic_52/usr/src/lib/libldap5/sources/ldap/common/free.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
2*7c478bd9Sstevel@tonic-gate 
3*7c478bd9Sstevel@tonic-gate /*
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
5*7c478bd9Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
6*7c478bd9Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
7*7c478bd9Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
10*7c478bd9Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11*7c478bd9Sstevel@tonic-gate  * implied. See the License for the specific language governing
12*7c478bd9Sstevel@tonic-gate  * rights and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
15*7c478bd9Sstevel@tonic-gate  * March 31, 1998.
16*7c478bd9Sstevel@tonic-gate  *
17*7c478bd9Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
18*7c478bd9Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
19*7c478bd9Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
20*7c478bd9Sstevel@tonic-gate  * Rights Reserved.
21*7c478bd9Sstevel@tonic-gate  *
22*7c478bd9Sstevel@tonic-gate  * Contributor(s):
23*7c478bd9Sstevel@tonic-gate  */
24*7c478bd9Sstevel@tonic-gate /*
25*7c478bd9Sstevel@tonic-gate  *  Copyright (c) 1994 The Regents of the University of Michigan.
26*7c478bd9Sstevel@tonic-gate  *  All rights reserved.
27*7c478bd9Sstevel@tonic-gate  */
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate  *  free.c - some free routines are included here to avoid having to
30*7c478bd9Sstevel@tonic-gate  *           link in lots of extra code when not using certain features
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #if 0
34*7c478bd9Sstevel@tonic-gate #ifndef lint
35*7c478bd9Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1994 The Regents of the University of Michigan.\nAll rights reserved.\n";
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate #endif
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate #include "ldap-int.h"
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate void
42*7c478bd9Sstevel@tonic-gate LDAP_CALL
43*7c478bd9Sstevel@tonic-gate ldap_getfilter_free( LDAPFiltDesc *lfdp )
44*7c478bd9Sstevel@tonic-gate {
45*7c478bd9Sstevel@tonic-gate     LDAPFiltList	*flp, *nextflp;
46*7c478bd9Sstevel@tonic-gate     LDAPFiltInfo	*fip, *nextfip;
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate     if ( lfdp == NULL ) {
49*7c478bd9Sstevel@tonic-gate 	return;
50*7c478bd9Sstevel@tonic-gate     }
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
53*7c478bd9Sstevel@tonic-gate 	for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
54*7c478bd9Sstevel@tonic-gate 	    nextfip = fip->lfi_next;
55*7c478bd9Sstevel@tonic-gate 	    NSLDAPI_FREE( fip->lfi_filter );
56*7c478bd9Sstevel@tonic-gate 	    NSLDAPI_FREE( fip->lfi_desc );
57*7c478bd9Sstevel@tonic-gate 	    NSLDAPI_FREE( fip );
58*7c478bd9Sstevel@tonic-gate 	}
59*7c478bd9Sstevel@tonic-gate 	nextflp = flp->lfl_next;
60*7c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( flp->lfl_pattern );
61*7c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( flp->lfl_delims );
62*7c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( flp->lfl_tag );
63*7c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( flp );
64*7c478bd9Sstevel@tonic-gate     }
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate     if ( lfdp->lfd_curvalcopy != NULL ) {
67*7c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( lfdp->lfd_curvalcopy );
68*7c478bd9Sstevel@tonic-gate     }
69*7c478bd9Sstevel@tonic-gate     if ( lfdp->lfd_curvalwords != NULL ) {
70*7c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( lfdp->lfd_curvalwords );
71*7c478bd9Sstevel@tonic-gate     }
72*7c478bd9Sstevel@tonic-gate     if ( lfdp->lfd_filtprefix != NULL ) {
73*7c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( lfdp->lfd_filtprefix );
74*7c478bd9Sstevel@tonic-gate     }
75*7c478bd9Sstevel@tonic-gate     if ( lfdp->lfd_filtsuffix != NULL ) {
76*7c478bd9Sstevel@tonic-gate 	NSLDAPI_FREE( lfdp->lfd_filtsuffix );
77*7c478bd9Sstevel@tonic-gate     }
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate     NSLDAPI_FREE( lfdp );
80*7c478bd9Sstevel@tonic-gate }
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate  * free a null-terminated array of pointers to mod structures. the
85*7c478bd9Sstevel@tonic-gate  * structures are freed, not the array itself, unless the freemods
86*7c478bd9Sstevel@tonic-gate  * flag is set.
87*7c478bd9Sstevel@tonic-gate  */
88*7c478bd9Sstevel@tonic-gate void
89*7c478bd9Sstevel@tonic-gate LDAP_CALL
90*7c478bd9Sstevel@tonic-gate ldap_mods_free( LDAPMod **mods, int freemods )
91*7c478bd9Sstevel@tonic-gate {
92*7c478bd9Sstevel@tonic-gate 	int	i;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAPMOD_ARRAY( mods )) {
95*7c478bd9Sstevel@tonic-gate 		return;
96*7c478bd9Sstevel@tonic-gate 	}
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 	for ( i = 0; mods[i] != NULL; i++ ) {
99*7c478bd9Sstevel@tonic-gate 		if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
100*7c478bd9Sstevel@tonic-gate 			if ( mods[i]->mod_bvalues != NULL ) {
101*7c478bd9Sstevel@tonic-gate 				ber_bvecfree( mods[i]->mod_bvalues );
102*7c478bd9Sstevel@tonic-gate 			}
103*7c478bd9Sstevel@tonic-gate 		} else if ( mods[i]->mod_values != NULL ) {
104*7c478bd9Sstevel@tonic-gate 			ldap_value_free( mods[i]->mod_values );
105*7c478bd9Sstevel@tonic-gate 		}
106*7c478bd9Sstevel@tonic-gate 		if ( mods[i]->mod_type != NULL ) {
107*7c478bd9Sstevel@tonic-gate 			NSLDAPI_FREE( mods[i]->mod_type );
108*7c478bd9Sstevel@tonic-gate 		}
109*7c478bd9Sstevel@tonic-gate 		NSLDAPI_FREE( (char *) mods[i] );
110*7c478bd9Sstevel@tonic-gate 	}
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate 	if ( freemods )
113*7c478bd9Sstevel@tonic-gate 		NSLDAPI_FREE( (char *) mods );
114*7c478bd9Sstevel@tonic-gate }
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate /*
118*7c478bd9Sstevel@tonic-gate  * ldap_memfree() is needed to ensure that memory allocated by the C runtime
119*7c478bd9Sstevel@tonic-gate  * assocated with libldap is freed by the same runtime code.
120*7c478bd9Sstevel@tonic-gate  */
121*7c478bd9Sstevel@tonic-gate void
122*7c478bd9Sstevel@tonic-gate LDAP_CALL
123*7c478bd9Sstevel@tonic-gate ldap_memfree( void *s )
124*7c478bd9Sstevel@tonic-gate {
125*7c478bd9Sstevel@tonic-gate 	if ( s != NULL ) {
126*7c478bd9Sstevel@tonic-gate 		NSLDAPI_FREE( s );
127*7c478bd9Sstevel@tonic-gate 	}
128*7c478bd9Sstevel@tonic-gate }
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate /*
132*7c478bd9Sstevel@tonic-gate  * ldap_ber_free() is just a cover for ber_free()
133*7c478bd9Sstevel@tonic-gate  * ber_free() checks for ber == NULL, so we don't bother.
134*7c478bd9Sstevel@tonic-gate  */
135*7c478bd9Sstevel@tonic-gate void
136*7c478bd9Sstevel@tonic-gate LDAP_CALL
137*7c478bd9Sstevel@tonic-gate ldap_ber_free( BerElement *ber, int freebuf )
138*7c478bd9Sstevel@tonic-gate {
139*7c478bd9Sstevel@tonic-gate 	ber_free( ber, freebuf );
140*7c478bd9Sstevel@tonic-gate }
141