heap-corruption

Dynamically allocating new object in constructor

点点圈 提交于 2019-12-02 02:40:07
So given this simple scenario: class A{ public: A(){ n = new int(10); } ~A(){ delete n; } int* n; }; int main(){ A* a = new A(); } Can this cause heap corruption (problems in general), since a-pointer hasn't finished allocating, while I'm making a new allocation? If so, using std::vector inside heap constructors in also prohibited, right? Thank you. Your a pointer has finished allocating . New works as follows (oversimplified) Allocate Construct So in your case Allocate A Construct A Allocate int Construct int - initialize Finish Construct A This ignores cases involving exceptions.. There is

How to turn GCStress on in Windows 7?

余生颓废 提交于 2019-11-30 13:52:46
I am debugging a GC heap corruption and came to the step where I want to try running the program under WinDbg + PageHeap + AppVerifier + GCStress. I found in the article Software crash: faulting module mscorwks.dll, version 1.1.4322.2379 that I can enable GCStress like this: reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f /v HeapVerify /t REG_DWORD /d 1 reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f /v StressLog /t REG_DWORD /d 1 reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f /v GCStress /t REG_DWORD /d 3 reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f /v

Do (statically linked) DLLs use a different heap than the main program?

五迷三道 提交于 2019-11-30 05:55:47
问题 I'm new to Windows programming and I've just "lost" two hours hunting a bug which everyone seems aware of: you cannot create an object on the heap in a DLL and destroy it in another DLL (or in the main program). I'm almost sure that on Linux/Unix this is NOT the case (if it is, please say it, but I'm pretty sure I did that thousands of times without problems...). At this point I have a couple of questions: 1) Do statically linked DLLs use a different heap than the main program? 2) Is the

How to turn GCStress on in Windows 7?

柔情痞子 提交于 2019-11-29 18:54:31
问题 I am debugging a GC heap corruption and came to the step where I want to try running the program under WinDbg + PageHeap + AppVerifier + GCStress. I found in the article Software crash: faulting module mscorwks.dll, version 1.1.4322.2379 that I can enable GCStress like this: reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f /v HeapVerify /t REG_DWORD /d 1 reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f /v StressLog /t REG_DWORD /d 1 reg.exe add "HKLM\SOFTWARE\Microsoft\

Immediate detection of heap corruption errors on Windows. How?

非 Y 不嫁゛ 提交于 2019-11-29 03:36:31
I can't sleep! :) I have a reasonably large project on Windows and encountered some heap corruption issues. I have read all SO, including this nice topic: How to debug heap corruption errors? , however nothing was suitable to help me out-of-the-box. Debug CRT and BoundsChecker detected heap corruptions, but addresses were always different and detections point were always far away from the actual memory overwrites. I have not slept till the middle of the night and crafted the following hack: DWORD PageSize = 0; inline void SetPageSize() { if ( !PageSize ) { SYSTEM_INFO sysInfo; GetSystemInfo(

Do (statically linked) DLLs use a different heap than the main program?

ぐ巨炮叔叔 提交于 2019-11-28 05:01:26
I'm new to Windows programming and I've just "lost" two hours hunting a bug which everyone seems aware of: you cannot create an object on the heap in a DLL and destroy it in another DLL (or in the main program). I'm almost sure that on Linux/Unix this is NOT the case (if it is, please say it, but I'm pretty sure I did that thousands of times without problems...). At this point I have a couple of questions: 1) Do statically linked DLLs use a different heap than the main program? 2) Is the statically linked DLL mapped in the same process space of the main program? (I'm quite sure the answer here

How to debug corruption in the managed heap

試著忘記壹切 提交于 2019-11-27 05:10:48
问题 My program throws an error which it cannot handle by a catch(Exception e) block and then it crashes: Access Violation Corrupted State Exception. This is the weird thing, because, as I know, corrupted state exceptions are thrown from unmanaged code, while here I get this exception while calling a StringBuilder method. The code runs in a background thread and crashes from time to time which cannot be easily reproduced. So I attached WinDbg to the process and have the following stack of the

Heap Corruption while using CreateWindowExW

吃可爱长大的小学妹 提交于 2019-11-27 02:26:44
I have some problems with heap corruption. The warning can be observed while using CreateWindowExW function. I know that it is usually a memory error, but how could I search it out in such situation? There are no new variables before calling CreateWindowExW and I can't step into this function. Here is the code. HWND GetMainWnd(HINSTANCE hInstance){ static HWND hWnd = NULL; if (hWnd) return hWnd; RETURN_AT_ERROR(hInstance, NULL); WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = MainWndProc; wcex.hInstance = hInstance; wcex.hCursor = :

Heap Corruption while using CreateWindowExW

白昼怎懂夜的黑 提交于 2019-11-26 10:03:39
问题 I have some problems with heap corruption. The warning can be observed while using CreateWindowExW function. I know that it is usually a memory error, but how could I search it out in such situation? There are no new variables before calling CreateWindowExW and I can\'t step into this function. Here is the code. HWND GetMainWnd(HINSTANCE hInstance){ static HWND hWnd = NULL; if (hWnd) return hWnd; RETURN_AT_ERROR(hInstance, NULL); WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; wcex.style = CS