About the error that occurs when using free () for the area not allocated by C language malloc

Error that appears when free () an area that is not malloc

malloctest.out(24922,0x1000cddc0) malloc: *** error for object 0x7ffeefbff5b0: pointer being freed was not allocated
malloctest.out(24922,0x1000cddc0) malloc: *** set a breakpoint in malloc_error_break to debug

If you initialize it with NULL immediately after declaring the variable, the above error will disappear. Because NULL is skipped by free ()?

List *a;
a = NULL;

I get the same error even if I do double free (). I understand that it is an error that appears when free () is performed for an unallocated area.

malloctest.out(25177,0x1000cddc0) malloc: *** error for object 0x100201bf0: pointer being freed was not allocated
malloctest.out(25177,0x1000cddc0) malloc: *** set a breakpoint in malloc_error_break to debug

This error is an error that appears when processing is performed on the premise that it is reserved for the unallocated area. The same error occurs even if the value is stored for the area after it is released by free ().

reference

[C language] For errors that seem to be caused by malloc --Currently C language ... --Yahoo! Chiebukuro https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q10116060110

Recommended Posts