오류:
삭제자 오류 해결: 할당 및 할당 취소 API 간의 불일치
비고
다음과 같이 정의되지 않은 동작으로 이어질 수 있는 일치하지 않는 메모리 작업의 런타임 검색을 사용하도록 설정합니다.
-
malloc는 쌍freedelete을 이겨delete[]야 합니다. -
new는 쌍deletefree을 이겨delete[]야 합니다. -
new[]는 쌍delete[]delete을 이겨free야 합니다.
Windows에서 alloc-dealloc-mismatch 오류 검색은 기본적으로 해제되어 있습니다. 사용하도록 설정하려면 프로그램을 실행하기 전에 환경 변수 set ASAN_OPTIONS=alloc_dealloc_mismatch=1 를 설정합니다.
예시
// example1.cpp
// Demonstrate alloc-dealloc-mismatch error
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
if (argc != 2) return -1;
switch (atoi(argv[1]))
{
case 1:
delete[](new int[10]);
break;
case 2:
delete (new int[10]); // Boom!
break;
default:
printf("arguments: 1: no error 2: runtime error\n");
return -1;
}
return 0;
}
Visual Studio 2019 버전 16.9 이상 개발자 명령 프롬프트에서 다음 명령을 실행하여 다음 예제 alloc_dealloc_mismatch를 확인합니다.
cl example1.cpp /fsanitize=address /Zi
set ASAN_OPTIONS=alloc_dealloc_mismatch=1
devenv /debugexe example1.exe 2
출력
참고 항목
AddressSanitizer 개요
AddressSanitizer 알려진 문제
AddressSanitizer 빌드 및 언어 참조
AddressSanitizer 런타임 참조
AddressSanitizer 섀도 바이트
AddressSanitizer 클라우드 또는 분산 테스트
AddressSanitizer 디버거 통합
AddressSanitizer 오류 예제