- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I`ve run into a problem with the malloc proxy and static variables (MSVS 2008, Win7). The problem is that tbb replaces memory allocation routines when the DllMain function is run, but this happens after the static variable initialization phase and they use the default allocation functions, but when the program finishes those static variables are destroyed with substituted routines, which sometimes leads (i wonder why not always?) to a crash. The program is most likely to crash when the static variable aquired some kind of resource (file or something else) during initialization and kept it until the program has finished. I think that if we want malloc proxy to work correctly, we must revert the memory function substitution done in DllMain when the dll is being detached from the process(it happens before static variables are destroyed), so that static variables could deallocate the memory using the same functions with which that memory was acuired.
I`ve run into a problem with the malloc proxy and static variables (MSVS 2008, Win7). The problem is that tbb replaces memory allocation routines when the DllMain function is run, but this happens after the static variable initialization phase and they use the default allocation functions, but when the program finishes those static variables are destroyed with substituted routines, which sometimes leads (i wonder why not always?) to a crash. The program is most likely to crash when the static variable aquired some kind of resource (file or something else) during initialization and kept it until the program has finished. I think that if we want malloc proxy to work correctly, we must revert the memory function substitution done in DllMain when the dll is being detached from the process(it happens before static variables are destroyed), so that static variables could deallocate the memory using the same functions with which that memory was acuired.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting soth
So I have a feature request to get a function in tbb_malloc library, which tells if the memory was allocated with tbb allocator (basically such method already exists, and it is the isRecognized function from MemoryAllocator.cpp, i`ve added it to the library`s exported functions to make thing work for me).
Link Copied
10 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi soth,
which tbb version do you use? 2.2 update 1 andnewer should have better support for the windows malloc replacement including static objects support improvements.
--Vladimir
which tbb version do you use? 2.2 update 1 andnewer should have better support for the windows malloc replacement including static objects support improvements.
--Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Vladimir Polin (Intel)
hi soth,
which tbb version do you use? 2.2 update 1 andnewer should have better support for the windows malloc replacement including static objects support improvements.
--Vladimir
which tbb version do you use? 2.2 update 1 andnewer should have better support for the windows malloc replacement including static objects support improvements.
--Vladimir
I`ve looked into the proxy.cpp file from the develepment release 20091101 and it seems to save the addresses of original free() functions, but i dont get when and where these functions are replaced back. Could someone explain it please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - soth
It`s tbb 2.2, i dont know for sure(not at home right now), but most likely it is the tbb22_20090809oss version. I need to update to get correct behavior?
I`ve looked into the proxy.cpp file from the develepment release 20091101 and it seems to save the addresses of original free() functions, but i dont get when and where these functions are replaced back. Could someone explain it please?
I`ve looked into the proxy.cpp file from the develepment release 20091101 and it seems to save the addresses of original free() functions, but i dont get when and where these functions are replaced back. Could someone explain it please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - soth
It`s tbb 2.2, i dont know for sure(not at home right now), but most likely it is the tbb22_20090809oss version. I need to update to get correct behavior?
I`ve looked into the proxy.cpp file from the develepment release 20091101 and it seems to save the addresses of original free() functions, but i dont get when and where these functions are replaced back. Could someone explain it please?
I`ve looked into the proxy.cpp file from the develepment release 20091101 and it seems to save the addresses of original free() functions, but i dont get when and where these functions are replaced back. Could someone explain it please?
Is this the 64-bit system? There is known issue with crash on application exit on 64-bit vista or win7 for this development release. If yes pls take the newer package.
Original functions are not replaced back. Even after final call of DLLmainproxy libaryis not unloaded and replaced functions can be called and executed.
--Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Vladimir Polin (Intel)
Is this the 64-bit system? There is known issue with crash on application exit on 64-bit vista or win7 for this development release. If yes pls take the newer package.
Original functions are not replaced back. Even after final call of DLLmainproxy libaryis not unloaded and replaced functions can be called and executed.
--Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - soth
Can ReplaceFunction be used to replace substituted functions back, given i have the address of the original function?
BTW in your case you cannot use realloc to resize data structures in static objects in the middle of the program.
--Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I`ve been playing around with tbb function replacement facilities again to patch the msvc crt libraries from my own dll and realized that just switching back to original allocation routines when the dll is detached from the process does not work for static objects, because they internally could allocate memory using patched functions during the program lifetime and free them when the dll is already detached, so it seems the correct way to do patching (as tbb_malloc_proxy and google tcmalloc does) is saving the original deallocation functions and using them when it is detected that the pointer was not allocated by the patched allocator. So I have a feature request to get a function in tbb_malloc library, which tells if the memory was allocated with tbb allocator (basically such method already exists, and it is the isRecognized function from MemoryAllocator.cpp, i`ve added it to the library`s exported functions to make thing work for me).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting soth
So I have a feature request to get a function in tbb_malloc library, which tells if the memory was allocated with tbb allocator (basically such method already exists, and it is the isRecognized function from MemoryAllocator.cpp, i`ve added it to the library`s exported functions to make thing work for me).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I`m fine with modifying the sources.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Soth,
Could you please tell me what you did to get rid of the crash? I run into the same situation (http://software.intel.com/en-us/forums/showthread.php?t=72457) and my app still crashes even after I tried to override the global new and delete operator with calls to scalable_malloc and scalable_free, totally bypassed tbbmalloc_proxy.dll and the function replacement stuff. I even exposed the isRecognized function as you suggested.
if (isRecognized(addr))
{
scalable_free(addr);
}
else
{
::operatordelete(addr); // call the default delete operator
}
After I made this change (link with tbbmalloc.lib directly, bypassing tbbmalloc_proxy.dll and memory function replacement), my app crashes HARD with access violation in the C runtime FreeHeap function.
Thanks for your help.
-Long

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page