上級 › free(): double free detected in tcache の原因と直し方 › パターン5
free(): double free detected in tcache の原因と直し方
同じポインタに対してfree()を2回呼び出したときに検出されるエラーです。
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(void) { 5 float *f = malloc(sizeof(float)); 6 *f = 2.5f; 7 free(f); 8 __________________________ ^ 9 return 0; 10 }
free(): double free detected in tcache 2
Aborted
空欄を埋めてコンパイル・実行を通す
float型でも同様です。解放後のポインタをそのまま残しておくと再度の解放に気づけません。
次の問題