]> git.sur5r.net Git - openldap/blob - libraries/libldap/free.c
Improved ldap_int_strtok. If strtok_r does not exists, it will be worked
[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         if(p != NULL) {
31                 free( p );
32         }
33 }
34
35 void
36 ldap_getfilter_free( LDAPFiltDesc *lfdp )
37 {
38     LDAPFiltList        *flp, *nextflp;
39     LDAPFiltInfo        *fip, *nextfip;
40
41     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
42         for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
43             nextfip = fip->lfi_next;
44             free( fip->lfi_filter );
45             free( fip->lfi_desc );
46             free( fip );
47         }
48         nextflp = flp->lfl_next;
49         free( flp->lfl_pattern );
50         free( flp->lfl_delims );
51         free( flp->lfl_tag );
52         free( flp );
53     }
54
55     if ( lfdp->lfd_curvalcopy != NULL ) {
56         free( lfdp->lfd_curvalcopy );
57     }
58     if ( lfdp->lfd_curvalwords != NULL ) {
59         free( lfdp->lfd_curvalwords );
60     }
61     if ( lfdp->lfd_filtprefix != NULL ) {
62         free( lfdp->lfd_filtprefix );
63     }
64     if ( lfdp->lfd_filtsuffix != NULL ) {
65         free( lfdp->lfd_filtsuffix );
66     }
67
68     free( lfdp );
69 }
70
71 /*
72  * free a null-terminated array of pointers to mod structures. the
73  * structures are freed, not the array itself, unless the freemods
74  * flag is set.
75  */
76
77 void
78 ldap_mods_free( LDAPMod **mods, int freemods )
79 {
80         int     i;
81
82         if ( mods == NULL )
83                 return;
84
85         for ( i = 0; mods[i] != NULL; i++ ) {
86                 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
87                         ber_bvecfree( mods[i]->mod_bvalues );
88                 } else {
89                         ldap_value_free( mods[i]->mod_values );
90                 }
91                 free( (char *) mods[i] );
92         }
93
94         if ( freemods )
95                 free( (char *) mods );
96 }