]> git.sur5r.net Git - openldap/blob - libraries/libldap/free.c
adf1d7b3c9747f34d58a8bfe35a41f855513e916
[openldap] / libraries / libldap / free.c
1 /*
2  *  Copyright (c) 1994 The Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  free.c - some free routines are included here to avoid having to
6  *           link in lots of extra code when not using certain features
7  */
8
9 #include "portable.h"
10
11 #ifndef lint 
12 static char copyright[] = "@(#) Copyright (c) 1994 The Regents of the University of Michigan.\nAll rights reserved.\n";
13 #endif
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <ctype.h>
18
19 #include <ac/string.h>
20 #include <ac/time.h>
21
22 #include "lber.h"
23 #include "ldap.h"
24
25 void
26 ldap_getfilter_free( LDAPFiltDesc *lfdp )
27 {
28     LDAPFiltList        *flp, *nextflp;
29     LDAPFiltInfo        *fip, *nextfip;
30
31     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
32         for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
33             nextfip = fip->lfi_next;
34             free( fip->lfi_filter );
35             free( fip->lfi_desc );
36             free( fip );
37         }
38         nextflp = flp->lfl_next;
39         free( flp->lfl_pattern );
40         free( flp->lfl_delims );
41         free( flp->lfl_tag );
42         free( flp );
43     }
44
45     if ( lfdp->lfd_curvalcopy != NULL ) {
46         free( lfdp->lfd_curvalcopy );
47     }
48     if ( lfdp->lfd_curvalwords != NULL ) {
49         free( lfdp->lfd_curvalwords );
50     }
51     if ( lfdp->lfd_filtprefix != NULL ) {
52         free( lfdp->lfd_filtprefix );
53     }
54     if ( lfdp->lfd_filtsuffix != NULL ) {
55         free( lfdp->lfd_filtsuffix );
56     }
57
58     free( lfdp );
59 }
60
61 /*
62  * free a null-terminated array of pointers to mod structures. the
63  * structures are freed, not the array itself, unless the freemods
64  * flag is set.
65  */
66
67 void
68 ldap_mods_free( LDAPMod **mods, int freemods )
69 {
70         int     i;
71
72         if ( mods == NULL )
73                 return;
74
75         for ( i = 0; mods[i] != NULL; i++ ) {
76                 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
77                         ber_bvecfree( mods[i]->mod_bvalues );
78                 } else {
79                         ldap_value_free( mods[i]->mod_values );
80                 }
81                 free( (char *) mods[i] );
82         }
83
84         if ( freemods )
85                 free( (char *) mods );
86 }