上級 › free(): double free detected in tcache の原因と直し方 › パターン3
free(): double free detected in tcache の原因と直し方
同じポインタに対してfree()を2回呼び出したときに検出されるエラーです。
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(void) { 5 char *buf = malloc(16); 6 free(buf); 7 _____________________ ^ 8 return 0; 9 }
free(): double free detected in tcache 2
Aborted
空欄を埋めてコンパイル・実行を通す
解放後すぐにNULLを代入する習慣をつけておけば、コードの離れた場所で誤って再度free()されても、NULLへのfree()は無害なので事故を防げます。
次の問題