/* free.c */1/* $OpenLDAP$ */2/* This work is part of OpenLDAP Software <http://www.openldap.org/>.3*4* Copyright 1998-2024 The OpenLDAP Foundation.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted only as authorized by the OpenLDAP9* Public License.10*11* A copy of this license is available in the file LICENSE in the12* top-level directory of the distribution or, alternatively, at13* <http://www.OpenLDAP.org/license.html>.14*/15/* Portions Copyright (c) 1994 The Regents of the University of Michigan.16* All rights reserved.17*/1819/*20* free.c - some free routines are included here to avoid having to21* link in lots of extra code when not using certain features22*/2324#include "portable.h"2526#include <stdio.h>27#include <ac/stdlib.h>2829#include <ac/string.h>30#include <ac/time.h>3132#include "ldap-int.h"3334/*35* C-API deallocator36*/37void38ldap_memfree( void *p )39{40LDAP_FREE( p );41}4243void44ldap_memvfree( void **v )45{46LDAP_VFREE( v );47}4849void *50ldap_memalloc( ber_len_t s )51{52return LDAP_MALLOC( s );53}5455void *56ldap_memcalloc( ber_len_t n, ber_len_t s )57{58return LDAP_CALLOC( n, s );59}6061void *62ldap_memrealloc( void* p, ber_len_t s )63{64return LDAP_REALLOC( p, s );65}6667char *68ldap_strdup( LDAP_CONST char *p )69{70return LDAP_STRDUP( p );71}7273/*74* free a null-terminated array of pointers to mod structures. the75* structures are freed, not the array itself, unless the freemods76* flag is set.77*/7879void80ldap_mods_free( LDAPMod **mods, int freemods )81{82int i;8384if ( mods == NULL )85return;8687for ( i = 0; mods[i] != NULL; i++ ) {88if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {89if( mods[i]->mod_bvalues != NULL )90ber_bvecfree( mods[i]->mod_bvalues );9192} else if( mods[i]->mod_values != NULL ) {93LDAP_VFREE( mods[i]->mod_values );94}9596if ( mods[i]->mod_type != NULL ) {97LDAP_FREE( mods[i]->mod_type );98}99100LDAP_FREE( (char *) mods[i] );101}102103if ( freemods ) {104LDAP_FREE( (char *) mods );105}106}107108109