Fri Mar 7 12:24:05 EST 2008 Pekka.Pessi@nokia.com
* su_alloc.c: using safe free git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7827 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
aeb1829220
commit
2abc13f368
|
@ -203,6 +203,12 @@ int (*_su_home_mutex_unlocker)(void *mutex);
|
||||||
|
|
||||||
void (*_su_home_destroy_mutexes)(void *mutex);
|
void (*_su_home_destroy_mutexes)(void *mutex);
|
||||||
|
|
||||||
|
#if HAVE_FREE_NULL
|
||||||
|
#define safefree(x) free((x))
|
||||||
|
#else
|
||||||
|
su_inline void safefree(void *b) { b ? free(b) : (void)0; }
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MEMLOCK(h) \
|
#define MEMLOCK(h) \
|
||||||
((void)((h) && (h)->suh_lock ? _su_home_locker((h)->suh_lock) : 0), (h)->suh_blocks)
|
((void)((h) && (h)->suh_lock ? _su_home_locker((h)->suh_lock) : 0), (h)->suh_blocks)
|
||||||
#define UNLOCK(h) ((void)((h) && (h)->suh_lock ? _su_home_unlocker((h)->suh_lock) : 0), NULL)
|
#define UNLOCK(h) ((void)((h) && (h)->suh_lock ? _su_home_unlocker((h)->suh_lock) : 0), NULL)
|
||||||
|
@ -457,7 +463,7 @@ void *sub_alloc(su_home_t *home,
|
||||||
home->suh_blocks = b2;
|
home->suh_blocks = b2;
|
||||||
|
|
||||||
if (sub && !sub->sub_auto)
|
if (sub && !sub->sub_auto)
|
||||||
free(sub);
|
safefree(sub);
|
||||||
sub = b2;
|
sub = b2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +506,7 @@ void *sub_alloc(su_home_t *home,
|
||||||
|
|
||||||
subhome->suh_blocks = su_hash_alloc(SUB_N);
|
subhome->suh_blocks = su_hash_alloc(SUB_N);
|
||||||
if (!subhome->suh_blocks)
|
if (!subhome->suh_blocks)
|
||||||
return (void)free(data), NULL;
|
return (void)safefree(data), NULL;
|
||||||
|
|
||||||
subhome->suh_size = (unsigned)size;
|
subhome->suh_size = (unsigned)size;
|
||||||
subhome->suh_blocks->sub_parent = home;
|
subhome->suh_blocks->sub_parent = home;
|
||||||
|
@ -555,7 +561,7 @@ void *su_home_new(isize_t size)
|
||||||
if (home->suh_blocks)
|
if (home->suh_blocks)
|
||||||
home->suh_blocks->sub_hauto = 0;
|
home->suh_blocks->sub_hauto = 0;
|
||||||
else
|
else
|
||||||
free(home), home = NULL;
|
safefree(home), home = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return home;
|
return home;
|
||||||
|
@ -670,7 +676,7 @@ int su_home_unref(su_home_t *home)
|
||||||
int hauto = sub->sub_hauto;
|
int hauto = sub->sub_hauto;
|
||||||
_su_home_deinit(home);
|
_su_home_deinit(home);
|
||||||
if (!hauto)
|
if (!hauto)
|
||||||
free(home);
|
safefree(home);
|
||||||
/* UNLOCK(home); */
|
/* UNLOCK(home); */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -827,7 +833,7 @@ void su_free(su_home_t *home, void *data)
|
||||||
UNLOCK(home);
|
UNLOCK(home);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data);
|
safefree(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check home consistency.
|
/** Check home consistency.
|
||||||
|
@ -977,8 +983,8 @@ void _su_home_deinit(su_home_t *home)
|
||||||
}
|
}
|
||||||
else if (su_is_preloaded(b, b->sub_nodes[i].sua_data))
|
else if (su_is_preloaded(b, b->sub_nodes[i].sua_data))
|
||||||
continue;
|
continue;
|
||||||
safe_free(b->sub_nodes[i].sua_data);
|
|
||||||
|
safefree(b->sub_nodes[i].sua_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,6 +202,28 @@ SAC_SU_DEFINE([SU_HAVE_TAGSTACK], 1, [
|
||||||
Define this as 1 if your compiler puts the variable argument list nicely in memory])
|
Define this as 1 if your compiler puts the variable argument list nicely in memory])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
### ======================================================================
|
||||||
|
### Test if free(0) fails
|
||||||
|
###
|
||||||
|
|
||||||
|
AC_CACHE_CHECK([for graceful free(0)],[ac_cv_free_null],[
|
||||||
|
ac_cv_free_null=no
|
||||||
|
|
||||||
|
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(int avc, char **av)
|
||||||
|
{
|
||||||
|
free(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
]])],[ac_cv_free_null=yes],[ac_cv_free_null=no],[ac_cv_free_null=no])])
|
||||||
|
|
||||||
|
if test $ac_cv_free_null = yes ; then
|
||||||
|
AC_DEFINE([HAVE_FREE_NULL], 1, [
|
||||||
|
Define this as 1 if your c library does not crash with free(0)])
|
||||||
|
fi
|
||||||
|
|
||||||
dnl ======================================================================
|
dnl ======================================================================
|
||||||
dnl Socket features
|
dnl Socket features
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue