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