]> git.sur5r.net Git - openldap/blob - libraries/libldap/free.c
Free strings returned by ldap_get_option().
[openldap] / libraries / libldap / free.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 /*  Portions
6  *  Copyright (c) 1994 The Regents of the University of Michigan.
7  *  All rights reserved.
8  *
9  *  free.c - some free routines are included here to avoid having to
10  *           link in lots of extra code when not using certain features
11  */
12
13 #include "portable.h"
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 /*
25  * C-API deallocator
26  */
27 void
28 ldap_memfree( void *p )
29 {
30         LDAP_FREE( p );
31 }
32
33 void *
34 ldap_memalloc( size_t s )
35 {
36         return LDAP_MALLOC( s );
37 }
38
39 void *
40 ldap_memcalloc( size_t n, size_t s )
41 {
42         return LDAP_CALLOC( n, s );
43 }
44
45 void *
46 ldap_memrealloc( void* p, size_t s )
47 {
48         return LDAP_REALLOC( p, s );
49 }
50
51 void
52 ldap_getfilter_free( LDAPFiltDesc *lfdp )
53 {
54     LDAPFiltList        *flp, *nextflp;
55     LDAPFiltInfo        *fip, *nextfip;
56
57     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
58         for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
59             nextfip = fip->lfi_next;
60             LDAP_FREE( fip->lfi_filter );
61             LDAP_FREE( fip->lfi_desc );
62             LDAP_FREE( fip );
63         }
64         nextflp = flp->lfl_next;
65         LDAP_FREE( flp->lfl_pattern );
66         LDAP_FREE( flp->lfl_delims );
67         LDAP_FREE( flp->lfl_tag );
68         LDAP_FREE( flp );
69     }
70
71     if ( lfdp->lfd_curvalcopy != NULL ) {
72         LDAP_FREE( lfdp->lfd_curvalcopy );
73     }
74     if ( lfdp->lfd_curvalwords != NULL ) {
75         LDAP_FREE( lfdp->lfd_curvalwords );
76     }
77     if ( lfdp->lfd_filtprefix != NULL ) {
78         LDAP_FREE( lfdp->lfd_filtprefix );
79     }
80     if ( lfdp->lfd_filtsuffix != NULL ) {
81         LDAP_FREE( lfdp->lfd_filtsuffix );
82     }
83
84     LDAP_FREE( lfdp );
85 }
86
87 /*
88  * free a null-terminated array of pointers to mod structures. the
89  * structures are freed, not the array itself, unless the freemods
90  * flag is set.
91  */
92
93 void
94 ldap_mods_free( LDAPMod **mods, int freemods )
95 {
96         int     i;
97
98         if ( mods == NULL )
99                 return;
100
101         for ( i = 0; mods[i] != NULL; i++ ) {
102                 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
103                         ber_bvecfree( mods[i]->mod_bvalues );
104                 } else {
105                         ldap_value_free( mods[i]->mod_values );
106                 }
107                 LDAP_FREE( (char *) mods[i] );
108         }
109
110         if ( freemods )
111                 LDAP_FREE( (char *) mods );
112 }