xref: /onnv-gate/usr/src/lib/libldap4/common/free.c (revision 3857:21b9b714e4ab)
1 /*
2  *
3  * Portions Copyright 1999 Sun Microsystems, Inc.  All rights reserved.
4  * Use is subject to license terms.
5  *
6  */
7 
8 #pragma ident	"%Z%%M%	%I%	%E% SMI"
9 
10 /*
11  *  Copyright (c) 1994 The Regents of the University of Michigan.
12  *  All rights reserved.
13  *
14  *  free.c - some free routines are included here to avoid having to
15  *           link in lots of extra code when not using certain features
16  */
17 
18 #ifndef lint
19 static char copyright[] = "@(#) Copyright (c) 1994 The Regents of the University of Michigan.\nAll rights reserved.\n";
20 #endif
21 
22 
23 #include <stdio.h>
24 #include <string.h>
25 #include <ctype.h>
26 #ifdef MACOS
27 #include <stdlib.h>
28 #include "macos.h"
29 #else /* MACOS */
30 #ifdef DOS
31 #include <malloc.h>
32 #include "msdos.h"
33 #else /* DOS */
34 #include <sys/types.h>
35 #include <stdlib.h>
36 #endif /* DOS */
37 #endif /* MACOS */
38 
39 #include "lber.h"
40 #include "ldap.h"
41 #include "ldap-private.h"
42 
43 void
ldap_getfilter_free(LDAPFiltDesc * lfdp)44 ldap_getfilter_free( LDAPFiltDesc *lfdp )
45 {
46     LDAPFiltList	*flp, *nextflp;
47     LDAPFiltInfo	*fip, *nextfip;
48 
49     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
50 	for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
51 	    nextfip = fip->lfi_next;
52 	    free( fip->lfi_filter );
53 	    free( fip->lfi_desc );
54 	    free( fip );
55 	}
56 	nextflp = flp->lfl_next;
57 	free( flp->lfl_pattern );
58 	free( flp->lfl_delims );
59 	free( flp->lfl_tag );
60 	free( flp );
61     }
62 
63     if ( lfdp->lfd_curvalcopy != NULL ) {
64 	free( lfdp->lfd_curvalcopy );
65     }
66     if ( lfdp->lfd_curvalwords != NULL ) {
67 	free( lfdp->lfd_curvalwords );
68     }
69     if ( lfdp->lfd_filtprefix != NULL ) {
70 	free( lfdp->lfd_filtprefix );
71     }
72     if ( lfdp->lfd_filtsuffix != NULL ) {
73 	free( lfdp->lfd_filtsuffix );
74     }
75 
76     free( lfdp );
77 }
78 
79 /*
80  * free a null-terminated array of pointers to mod structures. the
81  * structures are freed, not the array itself, unless the freemods
82  * flag is set.
83  */
84 
85 void
ldap_mods_free(LDAPMod ** mods,int freemods)86 ldap_mods_free( LDAPMod **mods, int freemods )
87 {
88 	int	i;
89 
90 	if ( mods == NULL )
91 		return;
92 
93 	for ( i = 0; mods[i] != NULL; i++ ) {
94 		if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
95 			ber_bvecfree( mods[i]->mod_bvalues );
96 		} else {
97 			ldap_value_free( mods[i]->mod_values );
98 		}
99 		if (mods[i]->mod_type)
100 			free(mods[i]->mod_type);
101 		free( (char *) mods[i] );
102 	}
103 
104 	if ( freemods )
105 		free( (char *) mods );
106 }
107