在类中检测到堆损坏(删除后),但仅在dll(而非exe)中使用时才会触发 [英] Heap corruption detected in class (after delete) but is only triggered when used within a dll, not an exe
问题描述
我有一个用于套接字通信的类(旧代码,不是我写的),当我这样做时(出于测试目的),我试图对其进行清理:
CCommSocket * tst = 新 CCommSocket;
删除 tst;
在dll中使用该代码时,我收到一个堆损坏调试错误,因为我看不到任何可能导致该类出现的东西,所以我将该类放入了主exe文件中,并且没有新闻/删除.问题.我猜想这与dll中的类有关.任何人都不知道是什么会导致堆损坏问题,例如在dll中而不是exe中吗?
...而且是的,这两个调用在dll中都紧挨着(暂时)...
-更新-
CCommSocket
的基类有一个bool
,我将其重铸为BOOL
,现在它可以正常工作.真的没有意义,特别是因为该类中还有另一个bool
. :doh:
-已解决-
http://www.codeproject.com/Messages/3797525/Re-class-size-doesnt-seem-to-be-determined-correct.aspx [解决方案
<似乎正在使用MFC作为DLL问题的一部分.您可能需要检查以下链接.
http://msdn.microsoft.com/en-us/library/zfz4xb9a.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/hw85e4bb.aspx [ ^ ]
在类之前的某个地方是否有任何#pragma pack(#)或__declspec(align(#))指令(可能会影响它)?
如果``基类''实现为预编译形式,或者在共享库中使用MFC时是MFC类,则默认打包支持为4(对于x86).如您所知,BOOL被定义为"int"类型,其大小为4个字节,而bool为1个字节.
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):
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[^]
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[^]
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.
这篇关于在类中检测到堆损坏(删除后),但仅在dll(而非exe)中使用时才会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!