aoyoo / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Windows tcmalloc: problem with _aligned_offset_malloc #285

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. void *p = _aligned_offset_malloc(65536, 8, 16);
2. _aligned_free(p);
3. Compile using MSVC against the debug libtcmalloc library

What is the expected output? What do you see instead?

Expect the code to run without error.  With thr debug library I get:
"c:\temp\google-perftools-1.6\src\tcmalloc.cc:1021] assertion 
failed: reinterpret_cast<uintptr_t>(ptr) % kPageSize == 0"

What version of the product are you using? On what operating system?

perftools 1.6 with either MSVC 8 or 9 on Windows XP

Please provide any additional information below.

tcmalloc on Windows hooks _aligned_malloc and _aligned_free but not 
other calls, such as _aligned_offset_malloc. 

This can generate assertions (in debug) or heap corruptions (in 
release) for programs using _aligned_offset_malloc. 

Possible solution 
  Simply remove hooking of _aligned_malloc and _aligned_free from tcmalloc. 

Rationale
These calls are implemented by the C runtime in terms of malloc and 
free, which are already hooked, so there seems little utility in hooking them. 

Note this requires a small change to tcmalloc_unittest.cc since it 
relies on being able to call free() against memory allocated with 
_aligned_malloc() which is *not* allowed with the actual Microsoft 
implementation. One option is to simply remove the use of _aligned_malloc from 
the unit test.

------ aligned_offset_malloc_test.cpp ------
#include <malloc.h> 
#include <stdio.h> 
#include <string.h> 

int main() 
{ 
  void *ptr = _aligned_offset_malloc(65536, 8, 16); 
  _aligned_free(ptr); 
} 

Original issue reported on code.google.com by roger....@gmail.com on 12 Nov 2010 at 1:59

GoogleCodeExporter commented 9 years ago
I'll removed the override of _aligned_malloc/free for the next release.  I'm 
not sure why I thought I needed to add them in.

Original comment by csilv...@gmail.com on 12 Nov 2010 at 10:35

GoogleCodeExporter commented 9 years ago
This should be fixed in perftools 1.7, just released.

Original comment by csilv...@gmail.com on 5 Feb 2011 at 12:24