Click here to Skip to main content
15,928,207 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CString return Pin
kakan16-Aug-07 0:12
professionalkakan16-Aug-07 0:12 
AnswerRe: CString return Pin
JudyL_MD16-Aug-07 2:34
JudyL_MD16-Aug-07 2:34 
QuestionRe: CString return Pin
David Crow16-Aug-07 3:14
David Crow16-Aug-07 3:14 
AnswerRe: CString return Pin
David Crow16-Aug-07 3:16
David Crow16-Aug-07 3:16 
Questioncan i use ofstream in VS 2005. Pin
Banks K15-Aug-07 20:50
Banks K15-Aug-07 20:50 
AnswerRe: can i use ofstream in VS 2005. Pin
jhwurmbach15-Aug-07 21:37
jhwurmbach15-Aug-07 21:37 
AnswerRe: can i use ofstream in VS 2005. Pin
John R. Shaw15-Aug-07 23:11
John R. Shaw15-Aug-07 23:11 
QuestionWinDbg - how to enable "Full-page heap" from Global Flags? [modified] Pin
devvvy15-Aug-07 20:13
devvvy15-Aug-07 20:13 
I've written a class with only three attributes:
<br />
class UTILITIES_API CStartupManager<br />
{<br />
...<br />
protected:<br />
	string				m_strConfigFileName;<br />
	ifstream			m_oConfigFile;<br />
	multimap<string, string>	m_oApplicationConfig;<br />
};<br />


The main application does this (and nothing else):
<br />
void InitApplication()<br />
{<br />
	CStartupManager oStartupManager;<br />
<br />
	oStartupManager.StartUp("app.config");<br />
<br />
	return;<br />
}<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
	InitApplication();<br />
   // DO NOTHING BESIDS INITIALIZATION (to keep things simple)<br />
	return 0;<br />
}<br />


I ran it and it crashed with message "User breakpoint called from code at 0x7c901230"..

I debugged with WinDbg as Visual Studio tells me that the fiasco happens in the destructor that dooes nothing -

<br />
CStartupManager::~CStartupManager()<br />
{<br />
   // DO NOTHING!<br />
	return;<br />
}<br />


Reading stack trace appear it's coming from attempt to free/deallocate the same chunk of memory twice:
<br />
NTDLL! 7c901230()<br />
NTDLL! 7c96cd80()<br />
NTDLL! 7c960af8()<br />
KERNEL32! 7c85e9cf()<br />
_CrtIsValidHeapPointer(const void * 0x004433a8) line 1697<br />
_free_dbg_lk(void * 0x004433a8, int 1) line 1044 + 9 bytes<br />
_free_dbg(void * 0x004433a8, int 1) line 1001 + 13 bytes<br />
free(void * 0x004433a8) line 956 + 11 bytes<br />
operator delete(void * 0x004433a8) line 7 + 9 bytes<br />
std::allocator::deallocate(void * 0x004433a8, unsigned int 33) line 64 + 38 bytes<br />
std::basic_string,std::allocator >::_Tidy(unsigned char 1) line 592<br />
std::basic_string,std::allocator >::~basic_string,std::allocator >() line 59 + 39 bytes<br />
CSomeClass::~CSomeClass() line 16 + 51 bytes


Following advice from my mentors, in hope of locating where the fault is exactly by debugging with WinDbg. Launch and attached to the target process, then run until I get:
<br />
Break instruction exception - code 80000003 (first chance)<br />


To drilldown further, "!analyze -v" seems to be telling me (the same information as Visual Studio) access violation happens in CStartupManager::~StartupManager (which does nothing)
<br />
...<br />
ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at "0x%08lx" referenced memory at "0x%08lx". The memory could not be "%s".<br />
BUGCHECK_STR:  ACCESS_VIOLATION<br />
...<br />
<br />
STACK_TEXT:  <br />
0012fb20 7c968b5e 01741000 018defb0 0012fb48 ntdll!RtlpDphIsNormalHeapBlock+0x81<br />
0012fb40 7c9697ae 00000007 00001002 018defb0 ntdll!RtlpDphNormalHeapValidate+0x2d<br />
0012fb84 7c960a4e 01740000 00000000 018defb0 ntdll!RtlpDebugPageHeapValidate+0x5a<br />
0012fbe8 7c85e9cf 01740000 00000000 018defb0 ntdll!RtlValidateHeap+0x36<br />
0012fbfc 1002ed00 01740000 00000000 018defb0 kernel32!HeapValidate+0x14<br />
0012fc20 1002e051 018defd0 0012fce8 0012fe14 Utilities!_CrtIsValidHeapPointer+0x120 [dbgheap.c @ 1697]<br />
0012fc3c 1002df81 018defd0 00000001 0012fce8 Utilities!_free_dbg_lk+0xa1 [dbgheap.c @ 1044]<br />
0012fc70 1002df0e 018defd0 00000001 0012fc8c Utilities!_free_dbg+0x41 [dbgheap.c @ 1001]<br />
0012fc80 1001605c 018defd0 0012fce8 100038b6 Utilities!free+0xe [dbgheap.c @ 956]<br />
0012fc8c 100038b6 018defd0 0012fd4c 0012fe14 Utilities!operator delete+0xc [delop.cpp @ 7]<br />
0012fce8 100030d2 018defd0 00000021 0012fda8 Utilities!std::allocator<char>::deallocate+0x26 [c:\program files\microsoft visual studio\vc98\include\xmemory @ 64]<br />
0012fd4c 100029b7 00000001 0012fe00 0012fe14 Utilities!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy+0x82 [c:\program files\microsoft visual studio\vc98\include\xstring @ 592]<br />
0012fda8 10006571 0012ff20 0012fe14 7ffd9000 Utilities!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >+0x27 [c:\program files\microsoft visual studio\vc98\include\xstring @ 59]<br />
0012fe0c 00402912 0012ff80 00d2f778 7ffd9000 Utilities!CStartupManager::~CStartupManager+0x71 [C:\...path...\Utilities\StartupManager.cpp @ 15]<br />
0012ff2c 0040298d 00d2f6f2 00d2f778 7ffd9000 DesktopAPI!InitApplication+0x92 [C:\...path...\DesktopAPI.cpp @ 17]<br />
0012ff80 00404849 00000001 0185afb0 0185cf50 DesktopAPI!main+0x1d <br />
[C:\...path...\DesktopAPI.cpp @ 24]<br />
0012ffc0 7c816fd7 00d2f6f2 00d2f778 7ffd9000 DesktopAPI!mainCRTStartup+0xe9 [crt0.c @ 206]<br />
0012fff0 00000000 00404760 00000000 78746341 kernel32!BaseProcessStart+0x23<br />


"It happen in destructor" is getting nowhere. And its seems that the fault wasn't caught instantly but rather detected when memory is freed -- how can I enable "Full-page heap" from Global Flags so I get the violation as it happens?

While WinDbg indicates this happens in destructor CStartupManager::~CStartupManager ... seems like it's actually happenning before that.


Reference here:
Full-Page Heap
Full-page heap should be enabled for individual processes, or under limited parameters for large processes, because of its high memory requirements. It cannot be enabled system-wide, because it is difficult to evaluate the required page file size. Using a page file that is too small with system-wide full-page heap renders the system unbootable.

The advantage of full-page heap is that it causes a process to access violate (AV) exactly at the point of failure. This makes the failure easy to debug. In order to be able to pinpoint failures, first use normal page heap to determine the range where a process is failing, and then use full-page heap on individual large-scale processes for that restricted class of allocations (that is, a specific size range or a specific library).

Normal Page Heap
Normal page heap can be used for the testing of large-scale processes without the high memory consumption that full-page heap requires. However, normal page heap delays detection until blocks are freed, thus making failures more difficult to debug.

In general, use normal page heap for initial large-scale processes testing. Then, if problems are detected, enable full-page heap for a restricted class of allocations in those processes.



Many thanks!
AnswerRe: WinDbg - how to enable &amp;amp;quot;Full-page heap&amp;amp;quot; from Global Flags? Pin
jhwurmbach15-Aug-07 21:52
jhwurmbach15-Aug-07 21:52 
GeneralRe: WinDbg - how to enable &amp;amp;quot;Full-page heap&amp;amp;quot; from Global Flags? Pin
devvvy15-Aug-07 21:59
devvvy15-Aug-07 21:59 
QuestionRe: WinDbg - how to enable &amp;amp;quot;Full-page heap&amp;amp;quot; from Global Flags? Pin
David Crow16-Aug-07 3:22
David Crow16-Aug-07 3:22 
QuestionAnother &quot;fatal error RC1107&quot; bug... Pin
xjohnx15-Aug-07 20:00
xjohnx15-Aug-07 20:00 
AnswerRe: Another &quot;fatal error RC1107&quot; bug... Pin
David Crow16-Aug-07 3:23
David Crow16-Aug-07 3:23 
GeneralRe: Another &quot;fatal error RC1107&quot; bug... Pin
xjohnx16-Aug-07 5:36
xjohnx16-Aug-07 5:36 
GeneralRe: Another &quot;fatal error RC1107&quot; bug... Pin
theCPkid5-May-09 20:13
theCPkid5-May-09 20:13 
GeneralRe: Another &quot;fatal error RC1107&quot; bug... Pin
Hofver14-Sep-09 22:49
Hofver14-Sep-09 22:49 
GeneralRe: Another "fatal error RC1107" bug... Pin
deyadav19-Jul-10 8:03
deyadav19-Jul-10 8:03 
GeneralRe: Another "fatal error RC1107" bug... Pin
copali14-Dec-10 5:14
copali14-Dec-10 5:14 
GeneralRe: Another "fatal error RC1107" bug... Pin
avinash.mp4-Feb-11 2:46
avinash.mp4-Feb-11 2:46 
AnswerRe: How To Make MessageBox on the Top of Other Window Pin
Bhaskar Priya15-Aug-07 20:12
Bhaskar Priya15-Aug-07 20:12 
GeneralRe: How To Make MessageBox on the Top of Other Window Pin
GauranG Shah15-Aug-07 20:49
GauranG Shah15-Aug-07 20:49 
GeneralRe: How To Make MessageBox on the Top of Other Window Pin
GauranG Shah15-Aug-07 21:09
GauranG Shah15-Aug-07 21:09 
QuestionGINA Pin
MozhdehQeraati15-Aug-07 19:54
MozhdehQeraati15-Aug-07 19:54 
QuestionPrint Crystal report XI from UI Thread in vc++ Pin
divya_prakash15-Aug-07 19:08
divya_prakash15-Aug-07 19:08 
QuestionCrystal report Help Pin
Neo Andreson15-Aug-07 19:05
Neo Andreson15-Aug-07 19:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.