Correct me if I am wrong, but I always thought, that the dlls have they own heap - therefore if you malloc something in DLL you are not able to free it in the EXE (or another DLL). I am not really sure about that, but it was told me in some years ago, while learning working with DLLs I allocated some resource in DLL1 and tried to free it in DLL2, getting the heap corruption message.