Why is vector deleting destructor being called as a result of a scalar delete?

后端 未结 5 1660
轮回少年
轮回少年 2020-12-31 11:23

I have some code that is crashing in a large system. However, the code essentially boils down to the following pseudo-code. I\'ve removed much of the detail, as I have tried

5条回答
  •  一向
    一向 (楼主)
    2020-12-31 11:39

    Microsoft provides the source for their C runtime; you can check there to see what _CrtIsValidHeapPointer does. On my installation, it's under C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\dbgheap.c.

    One other suggestion is to check the disassembly of

    delete newObj; // scalar delete
    

    and compare it to the disassembly generated for

    delete[] newObj;
    

    and

    delete pointerToClassLikeMyClassThatIsInExeAndNotDll;
    

    to test your theory about delete[] being called. Similarly, you could check the call stack for

    delete pointerToClassLikeMyClassThatIsInExeAndNotDll;
    

    to test your theory about mydll_d.dll!operator delete() versus myexe_d.exe!operator delete().

提交回复
热议问题