Home | History | Annotate | Line # | Download | only in libldap
      1 /*	$NetBSD: free.c,v 1.4 2025/09/05 21:16:21 christos Exp $	*/
      2 
      3 /* free.c */
      4 /* $OpenLDAP$ */
      5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6  *
      7  * Copyright 1998-2024 The OpenLDAP Foundation.
      8  * All rights reserved.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted only as authorized by the OpenLDAP
     12  * Public License.
     13  *
     14  * A copy of this license is available in the file LICENSE in the
     15  * top-level directory of the distribution or, alternatively, at
     16  * <http://www.OpenLDAP.org/license.html>.
     17  */
     18 /* Portions Copyright (c) 1994 The Regents of the University of Michigan.
     19  * All rights reserved.
     20  */
     21 
     22 /*
     23  *  free.c - some free routines are included here to avoid having to
     24  *           link in lots of extra code when not using certain features
     25  */
     26 
     27 #include <sys/cdefs.h>
     28 __RCSID("$NetBSD: free.c,v 1.4 2025/09/05 21:16:21 christos Exp $");
     29 
     30 #include "portable.h"
     31 
     32 #include <stdio.h>
     33 #include <ac/stdlib.h>
     34 
     35 #include <ac/string.h>
     36 #include <ac/time.h>
     37 
     38 #include "ldap-int.h"
     39 
     40 /*
     41  * C-API deallocator
     42  */
     43 void
     44 ldap_memfree( void *p )
     45 {
     46 	LDAP_FREE( p );
     47 }
     48 
     49 void
     50 ldap_memvfree( void **v )
     51 {
     52 	LDAP_VFREE( v );
     53 }
     54 
     55 void *
     56 ldap_memalloc( ber_len_t s )
     57 {
     58 	return LDAP_MALLOC( s );
     59 }
     60 
     61 void *
     62 ldap_memcalloc( ber_len_t n, ber_len_t s )
     63 {
     64 	return LDAP_CALLOC( n, s );
     65 }
     66 
     67 void *
     68 ldap_memrealloc( void* p, ber_len_t s )
     69 {
     70 	return LDAP_REALLOC( p, s );
     71 }
     72 
     73 char *
     74 ldap_strdup( LDAP_CONST char *p )
     75 {
     76 	return LDAP_STRDUP( p );
     77 }
     78 
     79 /*
     80  * free a null-terminated array of pointers to mod structures. the
     81  * structures are freed, not the array itself, unless the freemods
     82  * flag is set.
     83  */
     84 
     85 void
     86 ldap_mods_free( LDAPMod **mods, int freemods )
     87 {
     88 	int	i;
     89 
     90 	if ( mods == NULL )
     91 		return;
     92 
     93 	for ( i = 0; mods[i] != NULL; i++ ) {
     94 		if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
     95 			if( mods[i]->mod_bvalues != NULL )
     96 				ber_bvecfree( mods[i]->mod_bvalues );
     97 
     98 		} else if( mods[i]->mod_values != NULL ) {
     99 			LDAP_VFREE( mods[i]->mod_values );
    100 		}
    101 
    102 		if ( mods[i]->mod_type != NULL ) {
    103 			LDAP_FREE( mods[i]->mod_type );
    104 		}
    105 
    106 		LDAP_FREE( (char *) mods[i] );
    107 	}
    108 
    109 	if ( freemods ) {
    110 		LDAP_FREE( (char *) mods );
    111 	}
    112 }
    113