* Do not try to free() on buffers that have been allocated with the real

malloc, or we may crash unexpectedly, for instance if dlsym("free") calls
    malloc() then free() while free hasn't been loaded yet.
This commit is contained in:
Sam Hocevar
2008-06-10 16:21:17 +00:00
committed by sam
parent 18d87ea844
commit a530547a92
2 changed files with 10 additions and 4 deletions
+7 -1
View File
@@ -110,6 +110,7 @@ static int64_t dummy_offset = 0;
void _zz_mem_init(void)
{
LOADSYM(free);
LOADSYM(calloc);
LOADSYM(malloc);
LOADSYM(realloc);
@@ -156,7 +157,12 @@ void NEW(free)(void *ptr)
debug("%s(%p)", __func__, ptr);
return;
}
LOADSYM(free);
if(!ORIG(free))
{
/* FIXME: memory leak */
debug("%s(%p) IGNORED", __func__, ptr);
return;
}
ORIG(free)(ptr);
}
+3 -3
View File
@@ -102,13 +102,13 @@ void _zz_init(void)
{
char *tmp, *tmp2;
/* We need this as soon as possible */
_zz_mem_init();
tmp = getenv("ZZUF_DEBUG");
if(tmp)
_zz_debugfd = atoi(tmp);
/* We need this as soon as possible */
_zz_mem_init();
tmp = getenv("ZZUF_SEED");
if(tmp && *tmp)
_zz_setseed(atol(tmp));