some code cleanups
This commit is contained in:
@@ -426,29 +426,17 @@ void free_hook(void *ptr, const void *caller)
|
||||
|
||||
count_free++;
|
||||
uninstall_hooks();
|
||||
if (hdr->magic != MEMORY_HEADER_MAGIC)
|
||||
if (hdr->magic != MEMORY_HEADER_MAGIC ||
|
||||
tail->magic != MEMORY_TAIL_MAGIC)
|
||||
{
|
||||
fprintf(stderr, "freeing memory with corrupted header "
|
||||
"(%p, MAGIC 0x%x != 0x%x):\n",
|
||||
ptr, hdr->magic, MEMORY_HEADER_MAGIC);
|
||||
fprintf(stderr, "freeing invalid memory (%p): "
|
||||
"header magic 0x%x, tail magic 0x%x:\n",
|
||||
ptr, hdr->magic, tail->magic);
|
||||
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
|
||||
log_stack_frames(stack_frames, stack_frame_count);
|
||||
install_hooks();
|
||||
pthread_setschedparam(thread_id, oldpolicy, ¶ms);
|
||||
return;
|
||||
}
|
||||
if (tail->magic != MEMORY_TAIL_MAGIC)
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "freeing memory with corrupted tail "
|
||||
"(%p, MAGIC 0x%x != 0x%x):\n",
|
||||
ptr, tail->magic, MEMORY_TAIL_MAGIC);
|
||||
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
|
||||
log_stack_frames(stack_frames, stack_frame_count);
|
||||
install_hooks();
|
||||
pthread_setschedparam(thread_id, oldpolicy, &oldparams);
|
||||
return;
|
||||
}
|
||||
|
||||
/* remove item from list */
|
||||
if (hdr->next)
|
||||
{
|
||||
@@ -460,8 +448,9 @@ void free_hook(void *ptr, const void *caller)
|
||||
memset(hdr, MEMORY_FREE_PATTERN, hdr->bytes + sizeof(memory_header_t));
|
||||
|
||||
free(hdr);
|
||||
install_hooks();
|
||||
}
|
||||
|
||||
install_hooks();
|
||||
pthread_setschedparam(thread_id, oldpolicy, ¶ms);
|
||||
}
|
||||
|
||||
@@ -494,29 +483,14 @@ void *realloc_hook(void *old, size_t bytes, const void *caller)
|
||||
|
||||
count_realloc++;
|
||||
uninstall_hooks();
|
||||
if (hdr->magic != MEMORY_HEADER_MAGIC)
|
||||
if (hdr->magic != MEMORY_HEADER_MAGIC ||
|
||||
tail->magic != MEMORY_TAIL_MAGIC)
|
||||
{
|
||||
fprintf(stderr, "reallocating memory with corrupted header "
|
||||
"(%p, MAGIC 0x%x != 0x%x):\n",
|
||||
old, hdr->magic, MEMORY_HEADER_MAGIC);
|
||||
fprintf(stderr, "reallocating invalid memory (%p): "
|
||||
"header magic 0x%x, tail magic 0x%x:\n",
|
||||
old, hdr->magic, tail->magic);
|
||||
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
|
||||
log_stack_frames(stack_frames, stack_frame_count);
|
||||
install_hooks();
|
||||
pthread_setschedparam(thread_id, oldpolicy, &oldparams);
|
||||
raise(SIGKILL);
|
||||
return NULL;
|
||||
}
|
||||
if (tail->magic != MEMORY_TAIL_MAGIC)
|
||||
{
|
||||
fprintf(stderr, "reallocating memory with corrupted tail "
|
||||
"(%p, MAGIC 0x%x != 0x%x):\n",
|
||||
old, tail->magic, MEMORY_TAIL_MAGIC);
|
||||
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
|
||||
log_stack_frames(stack_frames, stack_frame_count);
|
||||
install_hooks();
|
||||
pthread_setschedparam(thread_id, oldpolicy, &oldparams);
|
||||
raise(SIGKILL);
|
||||
return NULL;
|
||||
}
|
||||
/* clear tail magic, allocate, set tail magic */
|
||||
memset(&tail->magic, MEMORY_ALLOC_PATTERN, sizeof(tail->magic));
|
||||
|
||||
Reference in New Issue
Block a user