가능한 중복 :
How to handle realloc when it fails due to memory?realloc이 실패 할 때 동적 배열 내의 포인터를 해제하는 방법은 무엇입니까?
이의 내가 realloc을가 실패 할 때
char **pointers_to_pChar = 0;
pointers_to_pChar = (char **)malloc(sizeof(char *) * SIZE);
for (i = 0; i < SIZE; ++i)
{
pointers_to_pChar[i] = malloc(sizeof(char) * 100));
}
//some stuff...
//time to realloc
pointers_to_pChar = realloc(pointers_to_pChar, sizeof(char *) * pointer_count + 1);
if (pointers_to_pChar == NULL)
{
//i have to free pointers in the array but i don't have access to array anymore...
}
가 어떻게 상황을 처리해야한다 포인터의 배열이 있다고 가정 해 봅시다? 배열 내의 각 포인터에 액세스하여 가능한 메모리 누수를 피하기 위해 해제해야합니다.