Re: C++ utility calling "delete this" fails with exception on 2008
Thanks for the input.
Code Sample I posted is not the actual code. Kind of psuedo code.
MyObjectBase doesn't have a virtual destructor, does it?
Yes. Destructor in classes are virtual.
Do all modules link against the same flavor of CRT DLL?
Dumpbin /imports of exe and two DLL all shows MSVCR80.DLL.
Embedded (into exe/dll) assembly info of the manifest in exe and two DLLs.
shows same version of VC80.CRT
assemblyIdentity type="win32" name="Microsoft.VC80.CRT"
version="8.0.50727.762" processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
What puzzles me that how 2008 is different from 2003. The prorgarm runs just
fine on win2k3 64-bit.
I fixed a __declspec (dllexport) / __declspec (dllimport) oddity. The Exe
was importing class with "__declspec (dllexport)" and I changed that but
program still fails. This time the frame on call stack is changed from
`vector deleting destructor' to `scalar deleting destructor'.
Is there a way to find out what MSVCR80!free+0xcd is trying to free?
Thanks.
"Igor Tandetnik" wrote:
RD <RD@discussions.microsoft.com> wrote:
I've a 32-bit command line C++ utility that fails on 2008 server. Code
compiled with VS2005. The utility works fine (and released) on
windows 2003 (64-bit too). I don't have any sample of reasonable
size, but here is the description.
1. Class Hierarchy in DLL
MyObjectBase{
AddRef() { Count++; return; }
Release() { if (Count <= 0) delete this; return;}
class MyIntClass : public MyObjectBase { }; // There are other
classes too in the hierarchy.
MyObjectBase doesn't have a virtual destructor, does it? Without virtual
destructor, your program exhibits undefined behavior: it is illegal to
delete an instance of a derived class via a pointer to its base, unless
that base has a virtual destructor.
Also - do you have a constructor that initialized Count?
This way when SmartPointer goes out of scope
the classes on the heap get deleted. Code in GetNums.cpp is like this.
int main() {
SmartPointer<MyCMGetIPListMessage> spMsg = new MyCMGetIPListMessage;
Do all modules link against the same flavor of CRT DLL? You are
allocating memory in one module (where main() is located), but freeing
it in another (where MyObjectBase::Release is located). This can only
work if both modules use the same memory manager, which requires them to
link to the same CRT DLL.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925