c++ - dynamically allocated string arrays failed to be deallocated -
i have following piece of code:
string * p = new string[8]; cout<<sizeof(p)<<endl; free(p);
which seems ok me failed with:
8 a.out(85837) malloc: *** error object 0x7fb5b3403ae8: pointer being freed not allocated *** set breakpoint in malloc_error_break debug abort trap: 6
another test on integer array worked. there special c++ string?
yap. new []
pairs delete []
. free()
ing causes undefined behavior.
Comments
Post a Comment