2003-11-26 15:16:36 +08:00
|
|
|
/* free.c */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 15:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2021-01-12 03:25:53 +08:00
|
|
|
* Copyright 1998-2021 The OpenLDAP Foundation.
|
2003-11-26 15:16:36 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
1998-08-09 08:43:13 +08:00
|
|
|
*
|
2003-11-26 15:16:36 +08:00
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* Portions Copyright (c) 1994 The Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1998-08-09 08:43:13 +08:00
|
|
|
* free.c - some free routines are included here to avoid having to
|
|
|
|
* link in lots of extra code when not using certain features
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/stdlib.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
#include "ldap-int.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-12-23 02:42:02 +08:00
|
|
|
/*
|
|
|
|
* C-API deallocator
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ldap_memfree( void *p )
|
|
|
|
{
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( p );
|
|
|
|
}
|
|
|
|
|
1999-06-02 03:08:27 +08:00
|
|
|
void
|
|
|
|
ldap_memvfree( void **v )
|
|
|
|
{
|
|
|
|
LDAP_VFREE( v );
|
|
|
|
}
|
|
|
|
|
1999-05-29 09:19:14 +08:00
|
|
|
void *
|
1999-06-19 07:53:05 +08:00
|
|
|
ldap_memalloc( ber_len_t s )
|
1999-05-29 09:19:14 +08:00
|
|
|
{
|
|
|
|
return LDAP_MALLOC( s );
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
1999-06-19 07:53:05 +08:00
|
|
|
ldap_memcalloc( ber_len_t n, ber_len_t s )
|
1999-05-29 09:19:14 +08:00
|
|
|
{
|
|
|
|
return LDAP_CALLOC( n, s );
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
1999-06-19 07:53:05 +08:00
|
|
|
ldap_memrealloc( void* p, ber_len_t s )
|
1999-05-29 09:19:14 +08:00
|
|
|
{
|
|
|
|
return LDAP_REALLOC( p, s );
|
1998-12-23 02:42:02 +08:00
|
|
|
}
|
|
|
|
|
1999-06-04 02:24:22 +08:00
|
|
|
char *
|
|
|
|
ldap_strdup( LDAP_CONST char *p )
|
|
|
|
{
|
|
|
|
return LDAP_STRDUP( p );
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* free a null-terminated array of pointers to mod structures. the
|
|
|
|
* structures are freed, not the array itself, unless the freemods
|
|
|
|
* flag is set.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
ldap_mods_free( LDAPMod **mods, int freemods )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( mods == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for ( i = 0; mods[i] != NULL; i++ ) {
|
|
|
|
if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
|
1999-06-03 05:38:48 +08:00
|
|
|
if( mods[i]->mod_bvalues != NULL )
|
|
|
|
ber_bvecfree( mods[i]->mod_bvalues );
|
|
|
|
|
|
|
|
} else if( mods[i]->mod_values != NULL ) {
|
|
|
|
LDAP_VFREE( mods[i]->mod_values );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mods[i]->mod_type != NULL ) {
|
|
|
|
LDAP_FREE( mods[i]->mod_type );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-06-03 05:38:48 +08:00
|
|
|
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( (char *) mods[i] );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-06-06 04:18:32 +08:00
|
|
|
if ( freemods ) {
|
1999-05-29 09:19:14 +08:00
|
|
|
LDAP_FREE( (char *) mods );
|
1999-06-06 04:18:32 +08:00
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|