Ejemplo n.º 1
0
static void
npw_mem_free (void *ptr, const char *file, int lineno)
{
  if (ptr == NULL)
    return;

  NPW_MemBlock *mem = (NPW_MemBlock *)((char *)ptr - (sizeof (*mem) + MALLOC_CHECK_GUARD_SIZE));
  if (mem->magic == NPW_MALLOC_MAGIC)
    {
      int underflow, overflow;
      if (!malloc_check_guards_ok (ptr, mem->alloc_size, &underflow, &overflow))
	{
	  if (underflow)
	    npw_printf ("ERROR: detected underflow of %d bytes\n"
			"  for block allocated at %s:%d\n"
			"  and released at %s:%d\n",
			underflow,
			mem->alloc_file, mem->alloc_lineno,
			file, lineno);
	  if (overflow)
	    npw_printf ("ERROR: detected overflow of %d bytes\n"
			"  for block allocated at %s:%d\n"
			"  and released at %s:%d\n",
			overflow,
			mem->alloc_file, mem->alloc_lineno,
			file, lineno);
	}
      get_malloc_hooks ()->memfree (mem, mem->real_size);
    }
  else
    {
      npw_printf("ERROR: block %p was not allocated with NPW_MemAlloc(), reverting to libc free()\n", ptr);
      free (ptr);
    }
}
Ejemplo n.º 2
0
void
NPW_MemFree (void *ptr)
{
    get_malloc_hooks ()->memfree (ptr);
}
Ejemplo n.º 3
0
void *
NPW_MemAlloc0 (uint32_t size)
{
    return get_malloc_hooks ()->memalloc0 (size);
}
Ejemplo n.º 4
0
static void *
npw_mem_alloc0 (uint32_t size, const char *file, int lineno)
{
  return npw_do_mem_alloc (get_malloc_hooks ()->memalloc0, size, file, lineno);
}