2 /* $OpenLDAP: pkg/ldap/libraries/libldap/free.c,v 1.22.2.3 2008/02/11 23:26:41 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
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
28 #include <ac/stdlib.h>
30 #include <ac/string.h>
39 ldap_memfree( void *p
)
45 ldap_memvfree( void **v
)
51 ldap_memalloc( ber_len_t s
)
53 return LDAP_MALLOC( s
);
57 ldap_memcalloc( ber_len_t n
, ber_len_t s
)
59 return LDAP_CALLOC( n
, s
);
63 ldap_memrealloc( void* p
, ber_len_t s
)
65 return LDAP_REALLOC( p
, s
);
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
81 ldap_mods_free( LDAPMod
**mods
, int freemods
)
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
] );
105 LDAP_FREE( (char *) mods
);