]> git.sur5r.net Git - openldap/blob - libraries/libldap/free.c
428f11f8284e8479f1a51279a995a9ae9210d10e
[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 <ac/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_memvfree( void **v )
35 {
36         LDAP_VFREE( v );
37 }
38
39 void *
40 ldap_memalloc( size_t s )
41 {
42         return LDAP_MALLOC( s );
43 }
44
45 void *
46 ldap_memcalloc( size_t n, size_t s )
47 {
48         return LDAP_CALLOC( n, s );
49 }
50
51 void *
52 ldap_memrealloc( void* p, size_t s )
53 {
54         return LDAP_REALLOC( p, s );
55 }
56
57 void
58 ldap_getfilter_free( LDAPFiltDesc *lfdp )
59 {
60     LDAPFiltList        *flp, *nextflp;
61     LDAPFiltInfo        *fip, *nextfip;
62
63     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
64         for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
65             nextfip = fip->lfi_next;
66             LDAP_FREE( fip->lfi_filter );
67             LDAP_FREE( fip->lfi_desc );
68             LDAP_FREE( fip );
69         }
70         nextflp = flp->lfl_next;
71         LDAP_FREE( flp->lfl_pattern );
72         LDAP_FREE( flp->lfl_delims );
73         LDAP_FREE( flp->lfl_tag );
74         LDAP_FREE( flp );
75     }
76
77     if ( lfdp->lfd_curvalcopy != NULL ) {
78         LDAP_FREE( lfdp->lfd_curvalcopy );
79     }
80     if ( lfdp->lfd_curvalwords != NULL ) {
81         LDAP_FREE( lfdp->lfd_curvalwords );
82     }
83     if ( lfdp->lfd_filtprefix != NULL ) {
84         LDAP_FREE( lfdp->lfd_filtprefix );
85     }
86     if ( lfdp->lfd_filtsuffix != NULL ) {
87         LDAP_FREE( lfdp->lfd_filtsuffix );
88     }
89
90     LDAP_FREE( lfdp );
91 }
92
93 /*
94  * free a null-terminated array of pointers to mod structures. the
95  * structures are freed, not the array itself, unless the freemods
96  * flag is set.
97  */
98
99 void
100 ldap_mods_free( LDAPMod **mods, int freemods )
101 {
102         int     i;
103
104         if ( mods == NULL )
105                 return;
106
107         for ( i = 0; mods[i] != NULL; i++ ) {
108                 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
109                         if( mods[i]->mod_bvalues != NULL )
110                                 ber_bvecfree( mods[i]->mod_bvalues );
111
112                 } else if( mods[i]->mod_values != NULL ) {
113                         LDAP_VFREE( mods[i]->mod_values );
114                 }
115
116                 if ( mods[i]->mod_type != NULL ) {
117                         LDAP_FREE( mods[i]->mod_type );
118                 }
119
120                 LDAP_FREE( (char *) mods[i] );
121         }
122
123         if ( freemods )
124                 LDAP_FREE( (char *) mods );
125 }