]> git.sur5r.net Git - openldap/blob - libraries/libldap/free.c
cleanup
[openldap] / libraries / libldap / free.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*  Portions
7  *  Copyright (c) 1994 The Regents of the University of Michigan.
8  *  All rights reserved.
9  *
10  *  free.c - some free routines are included here to avoid having to
11  *           link in lots of extra code when not using certain features
12  */
13
14 #include "portable.h"
15
16 #include <stdio.h>
17 #include <ac/stdlib.h>
18
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( ber_len_t s )
41 {
42         return LDAP_MALLOC( s );
43 }
44
45 void *
46 ldap_memcalloc( ber_len_t n, ber_len_t s )
47 {
48         return LDAP_CALLOC( n, s );
49 }
50
51 void *
52 ldap_memrealloc( void* p, ber_len_t s )
53 {
54         return LDAP_REALLOC( p, s );
55 }
56
57 char *
58 ldap_strdup( LDAP_CONST char *p )
59 {
60         return LDAP_STRDUP( p );
61 }
62
63 void
64 ldap_getfilter_free( LDAPFiltDesc *lfdp )
65 {
66     LDAPFiltList        *flp, *nextflp;
67     LDAPFiltInfo        *fip, *nextfip;
68
69     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
70         for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
71             nextfip = fip->lfi_next;
72             LDAP_FREE( fip->lfi_filter );
73             LDAP_FREE( fip->lfi_desc );
74             LDAP_FREE( fip );
75         }
76         nextflp = flp->lfl_next;
77         LDAP_FREE( flp->lfl_pattern );
78         LDAP_FREE( flp->lfl_delims );
79         LDAP_FREE( flp->lfl_tag );
80         LDAP_FREE( flp );
81     }
82
83     if ( lfdp->lfd_curvalcopy != NULL ) {
84         LDAP_FREE( lfdp->lfd_curvalcopy );
85     }
86     if ( lfdp->lfd_curvalwords != NULL ) {
87         LDAP_FREE( lfdp->lfd_curvalwords );
88     }
89     if ( lfdp->lfd_filtprefix != NULL ) {
90         LDAP_FREE( lfdp->lfd_filtprefix );
91     }
92     if ( lfdp->lfd_filtsuffix != NULL ) {
93         LDAP_FREE( lfdp->lfd_filtsuffix );
94     }
95
96     LDAP_FREE( lfdp );
97 }
98
99 /*
100  * free a null-terminated array of pointers to mod structures. the
101  * structures are freed, not the array itself, unless the freemods
102  * flag is set.
103  */
104
105 void
106 ldap_mods_free( LDAPMod **mods, int freemods )
107 {
108         int     i;
109
110         if ( mods == NULL )
111                 return;
112
113         for ( i = 0; mods[i] != NULL; i++ ) {
114                 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
115                         if( mods[i]->mod_bvalues != NULL )
116                                 ber_bvecfree( mods[i]->mod_bvalues );
117
118                 } else if( mods[i]->mod_values != NULL ) {
119                         LDAP_VFREE( mods[i]->mod_values );
120                 }
121
122                 if ( mods[i]->mod_type != NULL ) {
123                         LDAP_FREE( mods[i]->mod_type );
124                 }
125
126                 LDAP_FREE( (char *) mods[i] );
127         }
128
129         if ( freemods ) {
130                 LDAP_FREE( (char *) mods );
131         }
132 }