free.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* free.c */
  2. /* $OpenLDAP$ */
  3. /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  4. *
  5. * Copyright 1998-2024 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. * free.c - some free routines are included here to avoid having to
  21. * link in lots of extra code when not using certain features
  22. */
  23. #include "portable.h"
  24. #include <stdio.h>
  25. #include <ac/stdlib.h>
  26. #include <ac/string.h>
  27. #include <ac/time.h>
  28. #include "ldap-int.h"
  29. /*
  30. * C-API deallocator
  31. */
  32. void
  33. ldap_memfree( void *p )
  34. {
  35. LDAP_FREE( p );
  36. }
  37. void
  38. ldap_memvfree( void **v )
  39. {
  40. LDAP_VFREE( v );
  41. }
  42. void *
  43. ldap_memalloc( ber_len_t s )
  44. {
  45. return LDAP_MALLOC( s );
  46. }
  47. void *
  48. ldap_memcalloc( ber_len_t n, ber_len_t s )
  49. {
  50. return LDAP_CALLOC( n, s );
  51. }
  52. void *
  53. ldap_memrealloc( void* p, ber_len_t s )
  54. {
  55. return LDAP_REALLOC( p, s );
  56. }
  57. char *
  58. ldap_strdup( LDAP_CONST char *p )
  59. {
  60. return LDAP_STRDUP( p );
  61. }
  62. /*
  63. * free a null-terminated array of pointers to mod structures. the
  64. * structures are freed, not the array itself, unless the freemods
  65. * flag is set.
  66. */
  67. void
  68. ldap_mods_free( LDAPMod **mods, int freemods )
  69. {
  70. int i;
  71. if ( mods == NULL )
  72. return;
  73. for ( i = 0; mods[i] != NULL; i++ ) {
  74. if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
  75. if( mods[i]->mod_bvalues != NULL )
  76. ber_bvecfree( mods[i]->mod_bvalues );
  77. } else if( mods[i]->mod_values != NULL ) {
  78. LDAP_VFREE( mods[i]->mod_values );
  79. }
  80. if ( mods[i]->mod_type != NULL ) {
  81. LDAP_FREE( mods[i]->mod_type );
  82. }
  83. LDAP_FREE( (char *) mods[i] );
  84. }
  85. if ( freemods ) {
  86. LDAP_FREE( (char *) mods );
  87. }
  88. }