From: Oleg Starodumov on 28 Aug 2006 02:59 > I did try to use Application Verifier 3.2 to track the problem down, > and the program crashes leaving the following log: > Please now try the following: 1. In your _release_ build, disable optimizations, and enable debug information generation (/Zi compiler option; /debug, /debugtype:cv, /pdb:filename, /pdbtype:con linker options) Do Rebuild All and ensure that .pdb file is generated. 2. Run the release build under VC debugger with PageHeap enabled. Here is how to enable PageHeap: http://www.debuginfo.com/tips/userbpntdll.html Wait for access violations and hard-coded breakpoints reported by the debugger; usually an access violation should be reported exactly at the point where the heap gets corrupted. Regards, Oleg [VC++ MVP http://www.debuginfo.com/]
From: Jen on 28 Aug 2006 20:19 Oleg, Thank you so much for the information. I believe I have PageHeap properly enabled. I also disabled optimizations and enabled debug information, but wasn't able to get the /Zi compiler option. Also the /debugtype:cv doesn't appear and neither does /pdbtype:con. Do you know what option I need to change in the Linker or C/C++ tab to change these? I am using VC6. Thanks so much for the help! Jen Oleg Starodumov wrote: > > I did try to use Application Verifier 3.2 to track the problem down, > > and the program crashes leaving the following log: > > > > Please now try the following: > > 1. In your _release_ build, disable optimizations, and enable debug information generation > (/Zi compiler option; /debug, /debugtype:cv, /pdb:filename, /pdbtype:con linker options) > Do Rebuild All and ensure that .pdb file is generated. > > 2. Run the release build under VC debugger with PageHeap enabled. > Here is how to enable PageHeap: > http://www.debuginfo.com/tips/userbpntdll.html > > Wait for access violations and hard-coded breakpoints reported by the debugger; > usually an access violation should be reported exactly at the point where the heap > gets corrupted. > > Regards, > Oleg > [VC++ MVP http://www.debuginfo.com/]
From: Jen on 28 Aug 2006 20:44 Okay...I figured out how to set compiler / linker options and was able to debug the code. I found the line it crashes on. I am using an extension DLL, and it crashes on a function call to the DLL. FYI, I have to link to MFC Statically because of the extension dll. Here is the code: CString titleStr; GetProfileGraphTitle(2,titleStr); //Crashes here! CString GraphTitle = titleStr.GetBuffer(0); The function is in my DLL. Here is the prototype and function: __declspec(dllexport) void GetProfileGraphTitle(int num,CString &str); void GetProfileGraphTitle(int num,CString &str) { if(num >= 0) str = ProfileGraphs[num].GraphTitle; } The ProfileGraphs variable is a structure defined as follows: ProfileGraphData ProfileGraphs[NUM_PROFILE_GRAPHS]; struct ProfileGraphData { CString GraphTitle; CString ShortTitle; BOOL IsSelected; int Xunits; //type of X units int Yunits; //type of Y units - in user defined graphs this is the units selected by the user int NumCurves; int NumPoints; DynamicCurve theData[MAX_PROFILE_CURVES]; float MaxY; float MinY; float UserMaxY; float UserMinY; BOOL UseDefaults; float IgnoreLimit; int StartAvg; int EndAvg; //only for user defined graphs int GraphType[MAX_PROFILE_CURVES]; int ParamType; int CurveNum[MAX_PROFILE_CURVES]; int FileYUnits; int ParamNumber; }; #define MAX_PROFILE_CURVES 50 #define NUM_PROFILE_GRAPHS 50 Is there anything that you can think of that may be wrong? Or a place to start? Thanks!! Jen
From: David Ching on 28 Aug 2006 20:50 Jen" <leonard522(a)aol.com> wrote in message news:1156812269.733994.133260(a)74g2000cwt.googlegroups.com... > Okay...I figured out how to set compiler / linker options and was able > to debug the code. I found the line it crashes on. > > I am using an extension DLL, and it crashes on a function call to the > DLL. FYI, I have to link to MFC Statically because of the extension > dll. That's your problem, Jen. Extension DLL's need to have MFC dynamically linked, not statically linked. The issue is with static linking, there are two heap managers, one for the ..exe and one for the .dll. These two heaps don't know anything about each other. The .exe passes a CString to the dll. The DLL assigns the CString to something else. This causes the internal memory (call it 'buf') of CString to be reallocated (the old buffer is tossed, and a new one is allocated). When the old is tossed, it does a free(buf). This uses the DLL's heap manager to free it. But buf was initially allocated in the .exe, with the .exe's heap manager. So, freeing memory allocated by an incompatible heap manager yields CRASH! The short of it is, your Extension Dll MUST BE DYANMICALLY LINKED if you want to pass MFC objects like CString from the .exe. This causes only one heap manager to be used, avoiding the incompatiblity. BTW, it is documented that MFC Extension DLL's must be dynamically linked. -- David http://www.dcsoft.com Here is the code: > > CString titleStr; > GetProfileGraphTitle(2,titleStr); //Crashes here! > CString GraphTitle = titleStr.GetBuffer(0); > > The function is in my DLL. Here is the prototype and function: > > __declspec(dllexport) void GetProfileGraphTitle(int num,CString &str); > > void GetProfileGraphTitle(int num,CString &str) { > if(num >= 0) str = ProfileGraphs[num].GraphTitle; > } > > The ProfileGraphs variable is a structure defined as follows: > > ProfileGraphData ProfileGraphs[NUM_PROFILE_GRAPHS]; > > struct ProfileGraphData { > CString GraphTitle; > CString ShortTitle; > BOOL IsSelected; > int Xunits; //type of X units > int Yunits; //type of Y units - in user defined graphs this is the > units selected by the user > int NumCurves; > int NumPoints; > DynamicCurve theData[MAX_PROFILE_CURVES]; > float MaxY; > float MinY; > float UserMaxY; > float UserMinY; > BOOL UseDefaults; > float IgnoreLimit; > int StartAvg; > int EndAvg; > //only for user defined graphs > int GraphType[MAX_PROFILE_CURVES]; > int ParamType; > int CurveNum[MAX_PROFILE_CURVES]; > int FileYUnits; > int ParamNumber; > }; > #define MAX_PROFILE_CURVES 50 > #define NUM_PROFILE_GRAPHS 50 > > Is there anything that you can think of that may be wrong? Or a place > to start? Thanks!! > Jen >
From: Joseph M. Newcomer on 28 Aug 2006 20:43
Well '97 would have been VS 5.0; I was looking at the code in VS6.0, which is known as "VC98", suggesting that the bug was probably fixed in VS6. joe On Tue, 22 Aug 2006 22:13:32 -0700, "Ed Weir \(ComCast\)" <Anon(a)Maus.duh> wrote: >"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message >news:v2mne293slei1fmvg1civ2o0c3rpju45jp(a)4ax.com... >| Given how much I use CString::Format, I should have hit this bug years >ago, but I've never >| seen it. I suspect that there is memory damage elsewhere which is not >being caught in the >| debug mode and which the allocation pattern is sensitive enough that it >shows up. >| >| I truly hate memory damage bugs, which is why I've more and more adopted >ways to avoid >| ever having them. They rank among the most miserable bugs to track down. >| joe > >This bug was logged and repro'd by a lab tester some time ago - way back in ><spit> '97 or so by crackie (sure doesn't seem that long ago!). Looking at >the parser, I couldn't see anything mentioning a bug fix there. Sometimes, >you just have to avoid the ditch and get on with it. I never delved into >the GetBuffer routine - guess I should have assumed it would get the size >right... don't have time to do EVERYTHING!! After all. >- Ed. > >| On 22 Aug 2006 19:07:25 -0700, "Ajay Kalra" <ajaykalra(a)yahoo.com> wrote: >| >| >> I built it into a sandbox (_MBCS) and it worked OK for me; that doesn't >mean >| >> it's OK for her though... I could try it in UNICODE if needed later. >| > >| >I would assume that OP must have some special parameters that causes >| >failure on this line(according to OP). My guess is that problem is >| >elsewhere and it just happens to show up at this spot. CString is >| >pretty well used and tested. >| > >| >--- >| >Ajay >| Joseph M. Newcomer [MVP] >| email: newcomer(a)flounder.com >| Web: http://www.flounder.com >| MVP Tips: http://www.flounder.com/mvp_tips.htm Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm |