1/* free.c */ 2/* $OpenLDAP$ */ 3/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 4 * 5 * Copyright 1998-2011 The OpenLDAP Foundation. 6 * All rights reserved. 7 * 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. 11 * 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>. 15 */ 16/* Portions Copyright (c) 1994 The Regents of the University of Michigan. 17 * All rights reserved. 18 */ 19 20/* 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 23 */ 24 25#include "portable.h" 26 27#include <stdio.h> 28#include <ac/stdlib.h> 29 30#include <ac/string.h> 31#include <ac/time.h> 32 33#include "ldap-int.h" 34 35/* 36 * C-API deallocator 37 */ 38void 39ldap_memfree( void *p ) 40{ 41 LDAP_FREE( p ); 42} 43 44void 45ldap_memvfree( void **v ) 46{ 47 LDAP_VFREE( v ); 48} 49 50void * 51ldap_memalloc( ber_len_t s ) 52{ 53 return LDAP_MALLOC( s ); 54} 55 56void * 57ldap_memcalloc( ber_len_t n, ber_len_t s ) 58{ 59 return LDAP_CALLOC( n, s ); 60} 61 62void * 63ldap_memrealloc( void* p, ber_len_t s ) 64{ 65 return LDAP_REALLOC( p, s ); 66} 67 68char * 69ldap_strdup( LDAP_CONST char *p ) 70{ 71 return LDAP_STRDUP( p ); 72} 73 74/* 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. 78 */ 79 80void 81ldap_mods_free( LDAPMod **mods, int freemods ) 82{ 83 int i; 84 85 if ( mods == NULL ) 86 return; 87 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 ); 92 93 } else if( mods[i]->mod_values != NULL ) { 94 LDAP_VFREE( mods[i]->mod_values ); 95 } 96 97 if ( mods[i]->mod_type != NULL ) { 98 LDAP_FREE( mods[i]->mod_type ); 99 } 100 101 LDAP_FREE( (char *) mods[i] ); 102 } 103 104 if ( freemods ) { 105 LDAP_FREE( (char *) mods ); 106 } 107} 108