From: "Parag Jhavery" <Parag on 11 Feb 2005 04:29 I am facing a strange error when I compile my code in win32 debug mode. I am using MS VC++ 6.0 compiler and i am allocating and deallocating memory using new and delete operators. Below is a brief code flow of my application, i think it can be helpful. The code compiles fine but at the time of execution (Debug mode) it thrown an exception in file dbgheap.c at line 1044. BOOL CClassA::FunctionA() { PTBYTE lpMemRequired = NULL; m_CClassB.FunctionB(lpMemRequired) //This function will calculate and allocate the memory required. //This means memory is allocated in CClassB. if(lpMemRequired) delete []lpMemRequired; return; } This error started occuring after I made my application unicode compatible.
From: Scott McPhillips [MVP] on 11 Feb 2005 08:22 Parag Jhavery wrote: > I am facing a strange error when I compile my code in win32 debug mode. I am > using MS VC++ 6.0 compiler and i am allocating and deallocating memory using > new and delete operators. > Below is a brief code flow of my application, i think it can be helpful. > The code compiles fine but at the time of execution (Debug mode) it thrown > an exception in file dbgheap.c at line 1044. > BOOL CClassA::FunctionA() > { > PTBYTE lpMemRequired = NULL; > m_CClassB.FunctionB(lpMemRequired) //This function will calculate and > allocate the memory required. > //This means memory is allocated in CClassB. > if(lpMemRequired) > delete []lpMemRequired; > return; > } > > This error started occuring after I made my application unicode compatible. The error is likely to be in the declaration of FunctionB. If its parameter type is PTBYTE then this code cannot work. The pointer is passed by copy. Nothing that FunctionB does to the copy will affect the original variable. -- Scott McPhillips [VC++ MVP]
From: Joseph M. Newcomer on 11 Feb 2005 11:28 Most likely you are damaging the heap because somewhere in your code you are using byte count in place of character count. There is no useful information here. What relevance does this code have to the error you are seeing? For example, if the error occurs in the allocation, it means the heap damage has already occurred. You have shown nothing at all about FunctionB, so it is impossible to figure out what you are talking about in this example. But this sort of heap damage after a Unicode conversion is common, and most often indicates you have tried to store n Unicode characters into a heap buffer of n bytes. search for all uses of sizeof for a start. Then also make sure you have the sizeof(TCHAR) in all appropriate computations, either as a multiplier or divisor, as appropriate. Put code in your CWinApp::OnIdle of the form long CMyApp::OnIdle(long count) { if(count == 1) ASSERT(_heapchk() == HEAP_OK); // check _heapchk docs for spelling return CWinApp::OnIdle(count); } If you are doing damage, this catches it early. joe On Fri, 11 Feb 2005 01:29:07 -0800, "Parag Jhavery" <Parag Jhavery(a)discussions.microsoft.com> wrote: >I am facing a strange error when I compile my code in win32 debug mode. I am >using MS VC++ 6.0 compiler and i am allocating and deallocating memory using >new and delete operators. >Below is a brief code flow of my application, i think it can be helpful. >The code compiles fine but at the time of execution (Debug mode) it thrown >an exception in file dbgheap.c at line 1044. >BOOL CClassA::FunctionA() >{ > PTBYTE lpMemRequired = NULL; > m_CClassB.FunctionB(lpMemRequired) //This function will calculate and >allocate the memory required. > //This means memory is allocated in CClassB. > if(lpMemRequired) > delete []lpMemRequired; > return; >} > >This error started occuring after I made my application unicode compatible. Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Parag Jhavery on 14 Feb 2005 01:53 Hi Scott, Thanks for your reply... I would like to add few comments about the declaration of FunctionB. The code flow which i had posted earlier is something like this... BOOL CClassA::FunctionA() { PTBYTE lpMemRequired = NULL; m_CClassB.FunctionB(lpMemRequired) //This function will calculate and allocate the memory required. //This means memory is allocated in CClassB. if(lpMemRequired) delete []lpMemRequired; return; } Accoding to your comments I have verified and updated the function declation of FunctionB. FunctionB now looks something like.... CClass B::FunctionB(PTBYTE &lpMemRequired) The error is still persistant and I think it has something to do with unicode conversion. Let me know what you think about it... "Scott McPhillips [MVP]" wrote: > Parag Jhavery wrote: > > I am facing a strange error when I compile my code in win32 debug mode. I am > > using MS VC++ 6.0 compiler and i am allocating and deallocating memory using > > new and delete operators. > > Below is a brief code flow of my application, i think it can be helpful. > > The code compiles fine but at the time of execution (Debug mode) it thrown > > an exception in file dbgheap.c at line 1044. > > BOOL CClassA::FunctionA() > > { > > PTBYTE lpMemRequired = NULL; > > m_CClassB.FunctionB(lpMemRequired) //This function will calculate and > > allocate the memory required. > > //This means memory is allocated in CClassB. > > if(lpMemRequired) > > delete []lpMemRequired; > > return; > > } > > > > This error started occuring after I made my application unicode compatible. > > The error is likely to be in the declaration of FunctionB. If its > parameter type is PTBYTE then this code cannot work. The pointer is > passed by copy. Nothing that FunctionB does to the copy will affect the > original variable. > > -- > Scott McPhillips [VC++ MVP] > >
|
Pages: 1 Prev: Debug assertion in afxwin2.inl Next: bug in CWinApp::ProcessShellCommand |