Allocators Missing

Feb 24, 2011 at 5:00 PM

In the code that I have placed VLD into, it is unable to link to the msvrXXd.dll file (msvr90d.dll in my case) because in the following code:

void* CrtMfcPatch<TEMPLATE_ARGS>::crtd_malloc (size_t size)
    static malloc_t pcrtxxd_malloc = NULL;

    context_t context;
    HMODULE msvcrxxd;


    if (pcrtxxd_malloc == NULL) {
        // This is the first call to this function. Link to the real malloc.
        msvcrxxd = GetModuleHandle(crtddll);
        pcrtxxd_malloc = (malloc_t)vld._RGetProcAddress(msvcrxxd, "malloc");

    return vld._malloc(pcrtxxd_malloc, context, size);

msvcrxxd and pcrtxxd_malloc end up being NULLs.  When the allocator is called it jumps to address 0x00000000.

Is there something that I am missing?

Mar 7, 2011 at 7:24 PM

So, you say GetModuleHandle(crtddll) return NULL. Can you provide us sample?

Mar 7, 2011 at 9:52 PM


Yes it returns a NULL.

Actually I can't, I don't own the code and I don't have permission to submit a sample from it,  besides the code is extremely large and badly written, I would have a hard time pulling something out.  The program uses malloc/free and new/delete in the same source file, uses #define to create custom debug memory allocators and the code contain wonderfull code like:

mymemory = realloc(mymemory, new_memory_size) ;

I thought the problem may have to do with how the DLL was referenced or loaded 

Mar 7, 2011 at 9:54 PM

If you disable custom debug memory allocators and use ordinal allocators all works fine?

Mar 8, 2011 at 12:58 AM

I don't think the custom allocator is the problem because it still calls malloc.  It just seems that the GetModuleHandle is just not finding handle for the DLL,

Mar 10, 2011 at 7:43 PM
Edited Mar 21, 2011 at 11:03 AM

Another idea, can you reproduce bug and make memory dump (VS2010 Debug->Save Dump As)?

How create memory dump for debug report

Mar 10, 2011 at 8:53 PM

I don't have VS2010 but I could use autodump or process explorer from Sysinternals.  I'll look into trying to duplicate the problem.

Mar 15, 2011 at 8:11 PM

Yes, it's ok.

Mar 25, 2011 at 11:45 AM

I think, I found what caused that issue

Mar 25, 2011 at 1:37 PM

Great, I'll give it a try.


Mar 25, 2011 at 4:08 PM

Now fixed

Mar 25, 2011 at 9:34 PM

Can you test 2.1 version ?