重複の可能性:
メモリが原因で失敗した場合に 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...
}
realloc が失敗した場合、どのように対処すればよいですか? メモリ リークの可能性を回避するために、配列内の各ポインターにアクセスして解放する必要があります。