]> git.sur5r.net Git - openldap/blob - libraries/libldap/free.c
ebf2d623c5709b4321018c748883ecdd2e6e0df3
[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
18 #include <ac/ctype.h>
19 #include <ac/string.h>
20 #include <ac/time.h>
21
22 #include "ldap-int.h"
23
24 void
25 ldap_getfilter_free( LDAPFiltDesc *lfdp )
26 {
27     LDAPFiltList        *flp, *nextflp;
28     LDAPFiltInfo        *fip, *nextfip;
29
30     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
31         for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
32             nextfip = fip->lfi_next;
33             free( fip->lfi_filter );
34             free( fip->lfi_desc );
35             free( fip );
36         }
37         nextflp = flp->lfl_next;
38         free( flp->lfl_pattern );
39         free( flp->lfl_delims );
40         free( flp->lfl_tag );
41         free( flp );
42     }
43
44     if ( lfdp->lfd_curvalcopy != NULL ) {
45         free( lfdp->lfd_curvalcopy );
46     }
47     if ( lfdp->lfd_curvalwords != NULL ) {
48         free( lfdp->lfd_curvalwords );
49     }
50     if ( lfdp->lfd_filtprefix != NULL ) {
51         free( lfdp->lfd_filtprefix );
52     }
53     if ( lfdp->lfd_filtsuffix != NULL ) {
54         free( lfdp->lfd_filtsuffix );
55     }
56
57     free( lfdp );
58 }
59
60 /*
61  * free a null-terminated array of pointers to mod structures. the
62  * structures are freed, not the array itself, unless the freemods
63  * flag is set.
64  */
65
66 void
67 ldap_mods_free( LDAPMod **mods, int freemods )
68 {
69         int     i;
70
71         if ( mods == NULL )
72                 return;
73
74         for ( i = 0; mods[i] != NULL; i++ ) {
75                 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
76                         ber_bvecfree( mods[i]->mod_bvalues );
77                 } else {
78                         ldap_value_free( mods[i]->mod_values );
79                 }
80                 free( (char *) mods[i] );
81         }
82
83         if ( freemods )
84                 free( (char *) mods );
85 }