LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
HDC hdc{};
PAINTSTRUCT ps{};
int i{};
int* ptr = NULL;
TCHAR str[128]{};
switch (iMessage) {
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
ptr = (int*)VirtualAlloc(NULL, sizeof(int) * 10, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (ptr != NULL) {
for (i = 0; i < 10; i++) {
wsprintfW(str, TEXT("%d"), ptr[i] = i * 2);
TextOut(hdc, 10, i * 20, str, lstrlenW(str));
}
VirtualFree(ptr, _msize(ptr), MEM_DECOMMIT); // C6250경고 표시
VirtualFree(ptr, 0, MEM_RELEASE);
}
EndPaint(hWnd, &ps);
return(0);
case WM_DESTROY:
PostQuitMessage(0);
return(0);
}
DefWindowProcW(hWnd, iMessage, wParam, lParam);
}
밑줄그은 부분에서 자꾸만 C6250 메모리 누수 경고가 뜨는데 해결방법을 알고싶습니다. 분명 책에는 확정된 메모리를 해제하려면 확정 해제 후 예약해제라고 써 있는데 왜 메모리 누수 경고가 뜨는지 알고싶으며, 해결방법을 무엇인지 알고싶습니다.
답변부탁드립니다.

김민수
error code: 522
error code: 522
|
|