Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I have a class that I use for socket communications (old code, not written by me) that I'm attempting to clean up, when I do this (for testing purposes):
C++
CCommSocket *tst = new CCommSocket;
delete tst;

I get a heap corruption debug error when the code is used in a dll, since I couldn't see anything that could cause that within the class, I took the class and placed it within the main exe and it news/deletes with no problem. I'm guessing this has something to do with the class being in the dll. Anyone have any idea what would cause a heap corruption problem such as this within a dll and not an exe?

...and yes, the calls are right next to one another (for now), both within the dll...

--Update--
The base class for CCommSocket had a bool that I recast to BOOL and now it works fine. Doesn't really make sense, specially because there's another bool in the class as well. :doh:

--SOLVED--
http://www.codeproject.com/Messages/3797525/Re-class-size-doesnt-seem-to-be-determined-correct.aspx[^]
Posted
Updated 5-Mar-11 11:35am
v6

It seems to be using MFC as part of a DLL issue. You may need to check following links.

http://msdn.microsoft.com/en-us/library/zfz4xb9a.aspx[^]

http://msdn.microsoft.com/en-us/library/hw85e4bb.aspx[^]
 
Share this answer
 
Comments
Dalek Dave 4-Mar-11 19:33pm    
Good Links.
Albert Holguin 4-Mar-11 23:05pm    
Yeah nice links but really have nothing to do with my question... the code seems to work just can't delete properly, creating a memory leak.
Is there any #pragma pack(#) or __declspec(align(#)) directive somewhere (may affect it) before your class?

If the base class' implementation is in pre-compiled form or it is an MFC class while using MFC in shared libs, default packing alingment is 4 (for x86). As you may know, BOOL is defined as type "int" which is 4 bytes in size while bool is 1 byte.
 
Share this answer
 
Comments
Albert Holguin 5-Mar-11 17:33pm    
A few more details if anyone's interested (thanks to ozer for helping) are included in a link in the main question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900