libs: Import code from upstream openldap 2.5.13.
[wine.git] / libs / ldap / libldap / free.c
blob4d09eeef452f18aeaab1e18d8ff1f478db3d7615
1 /* free.c */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2022 The OpenLDAP Foundation.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
10 * Public License.
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
16 /* Portions Copyright (c) 1994 The Regents of the University of Michigan.
17 * All rights reserved.
21 * free.c - some free routines are included here to avoid having to
22 * link in lots of extra code when not using certain features
25 #include "portable.h"
27 #include <stdio.h>
28 #include <ac/stdlib.h>
30 #include <ac/string.h>
31 #include <ac/time.h>
33 #include "ldap-int.h"
36 * C-API deallocator
38 void
39 ldap_memfree( void *p )
41 LDAP_FREE( p );
44 void
45 ldap_memvfree( void **v )
47 LDAP_VFREE( v );
50 void *
51 ldap_memalloc( ber_len_t s )
53 return LDAP_MALLOC( s );
56 void *
57 ldap_memcalloc( ber_len_t n, ber_len_t s )
59 return LDAP_CALLOC( n, s );
62 void *
63 ldap_memrealloc( void* p, ber_len_t s )
65 return LDAP_REALLOC( p, s );
68 char *
69 ldap_strdup( LDAP_CONST char *p )
71 return LDAP_STRDUP( p );
75 * free a null-terminated array of pointers to mod structures. the
76 * structures are freed, not the array itself, unless the freemods
77 * flag is set.
80 void
81 ldap_mods_free( LDAPMod **mods, int freemods )
83 int i;
85 if ( mods == NULL )
86 return;
88 for ( i = 0; mods[i] != NULL; i++ ) {
89 if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
90 if( mods[i]->mod_bvalues != NULL )
91 ber_bvecfree( mods[i]->mod_bvalues );
93 } else if( mods[i]->mod_values != NULL ) {
94 LDAP_VFREE( mods[i]->mod_values );
97 if ( mods[i]->mod_type != NULL ) {
98 LDAP_FREE( mods[i]->mod_type );
101 LDAP_FREE( (char *) mods[i] );
104 if ( freemods ) {
105 LDAP_FREE( (char *) mods );