]> git.sur5r.net Git - openldap/blob - libraries/libldap/free.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / libraries / libldap / free.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-1999 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/ctype.h>
20 #include <ac/string.h>
21 #include <ac/time.h>
22
23 #include "ldap-int.h"
24
25 /*
26  * C-API deallocator
27  */
28 void
29 ldap_memfree( void *p )
30 {
31         LDAP_FREE( p );
32 }
33
34 void
35 ldap_memvfree( void **v )
36 {
37         LDAP_VFREE( v );
38 }
39
40 void *
41 ldap_memalloc( ber_len_t s )
42 {
43         return LDAP_MALLOC( s );
44 }
45
46 void *
47 ldap_memcalloc( ber_len_t n, ber_len_t s )
48 {
49         return LDAP_CALLOC( n, s );
50 }
51
52 void *
53 ldap_memrealloc( void* p, ber_len_t s )
54 {
55         return LDAP_REALLOC( p, s );
56 }
57
58 char *
59 ldap_strdup( LDAP_CONST char *p )
60 {
61         return LDAP_STRDUP( p );
62 }
63
64 void
65 ldap_getfilter_free( LDAPFiltDesc *lfdp )
66 {
67     LDAPFiltList        *flp, *nextflp;
68     LDAPFiltInfo        *fip, *nextfip;
69
70     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
71         for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
72             nextfip = fip->lfi_next;
73             LDAP_FREE( fip->lfi_filter );
74             LDAP_FREE( fip->lfi_desc );
75             LDAP_FREE( fip );
76         }
77         nextflp = flp->lfl_next;
78         LDAP_FREE( flp->lfl_pattern );
79         LDAP_FREE( flp->lfl_delims );
80         LDAP_FREE( flp->lfl_tag );
81         LDAP_FREE( flp );
82     }
83
84     if ( lfdp->lfd_curvalcopy != NULL ) {
85         LDAP_FREE( lfdp->lfd_curvalcopy );
86     }
87     if ( lfdp->lfd_curvalwords != NULL ) {
88         LDAP_FREE( lfdp->lfd_curvalwords );
89     }
90     if ( lfdp->lfd_filtprefix != NULL ) {
91         LDAP_FREE( lfdp->lfd_filtprefix );
92     }
93     if ( lfdp->lfd_filtsuffix != NULL ) {
94         LDAP_FREE( lfdp->lfd_filtsuffix );
95     }
96
97     LDAP_FREE( lfdp );
98 }
99
100 /*
101  * free a null-terminated array of pointers to mod structures. the
102  * structures are freed, not the array itself, unless the freemods
103  * flag is set.
104  */
105
106 void
107 ldap_mods_free( LDAPMod **mods, int freemods )
108 {
109         int     i;
110
111         if ( mods == NULL )
112                 return;
113
114         for ( i = 0; mods[i] != NULL; i++ ) {
115                 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
116                         if( mods[i]->mod_bvalues != NULL )
117                                 ber_bvecfree( mods[i]->mod_bvalues );
118
119                 } else if( mods[i]->mod_values != NULL ) {
120                         LDAP_VFREE( mods[i]->mod_values );
121                 }
122
123                 if ( mods[i]->mod_type != NULL ) {
124                         LDAP_FREE( mods[i]->mod_type );
125                 }
126
127                 LDAP_FREE( (char *) mods[i] );
128         }
129
130         if ( freemods ) {
131                 LDAP_FREE( (char *) mods );
132         }
133 }