Back to index

openldap  2.4.31
free.c
Go to the documentation of this file.
00001 /* free.c */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 1998-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* Portions Copyright (c) 1994 The Regents of the University of Michigan.
00017  * All rights reserved.
00018  */
00019 
00020 /*
00021  *  free.c - some free routines are included here to avoid having to
00022  *           link in lots of extra code when not using certain features
00023  */
00024 
00025 #include "portable.h"
00026 
00027 #include <stdio.h>
00028 #include <ac/stdlib.h>
00029 
00030 #include <ac/string.h>
00031 #include <ac/time.h>
00032 
00033 #include "ldap-int.h"
00034 
00035 /*
00036  * C-API deallocator
00037  */
00038 void
00039 ldap_memfree( void *p )
00040 {
00041        LDAP_FREE( p );
00042 }
00043 
00044 void
00045 ldap_memvfree( void **v )
00046 {
00047        LDAP_VFREE( v );
00048 }
00049 
00050 void *
00051 ldap_memalloc( ber_len_t s )
00052 {
00053        return LDAP_MALLOC( s );
00054 }
00055 
00056 void *
00057 ldap_memcalloc( ber_len_t n, ber_len_t s )
00058 {
00059        return LDAP_CALLOC( n, s );
00060 }
00061 
00062 void *
00063 ldap_memrealloc( void* p, ber_len_t s )
00064 {
00065        return LDAP_REALLOC( p, s );
00066 }
00067 
00068 char *
00069 ldap_strdup( LDAP_CONST char *p )
00070 {
00071        return LDAP_STRDUP( p );
00072 }
00073 
00074 /*
00075  * free a null-terminated array of pointers to mod structures. the
00076  * structures are freed, not the array itself, unless the freemods
00077  * flag is set.
00078  */
00079 
00080 void
00081 ldap_mods_free( LDAPMod **mods, int freemods )
00082 {
00083        int    i;
00084 
00085        if ( mods == NULL )
00086               return;
00087 
00088        for ( i = 0; mods[i] != NULL; i++ ) {
00089               if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
00090                      if( mods[i]->mod_bvalues != NULL )
00091                             ber_bvecfree( mods[i]->mod_bvalues );
00092 
00093               } else if( mods[i]->mod_values != NULL ) {
00094                      LDAP_VFREE( mods[i]->mod_values );
00095               }
00096 
00097               if ( mods[i]->mod_type != NULL ) {
00098                      LDAP_FREE( mods[i]->mod_type );
00099               }
00100 
00101               LDAP_FREE( (char *) mods[i] );
00102        }
00103 
00104        if ( freemods ) {
00105               LDAP_FREE( (char *) mods );
00106        }
00107 }