Segmentation error after free (), what are the common reasons for this?

I get a segmentation error after freewith a specific pointer:

free(studentDB->name);

I can get its value without any errors or warnings:

printf("[DBG] studentDB->name: %s\n", studentDB->name);

However, as I said, the program fires when I try to free it. What are the most common reasons for a team freeleading to a segmentation error?

+5
source share
7 answers

If you are not malloc(), you cannot free()him. Where from studentDB->name?

+13
source

You may have either freed () or overwritten the malloc information preceding the block with a buffer overflow

+2

- . , . , , free, , .

+2

free , malloc, free 'd.

, , studentDB->name.

0

studentDB->name? , , free, -! , malloc d strdup d.

, , , name...

, , , .

0

, studentDB segfault, studentDB NULL.

0

manpage:

free (ptr) ptr, malloc(), calloc() realloc(). , free (ptr) , undefined . ptr NULL, .

:

  • studentDB -NULL- /, ""?
  • Is the space pointed to by studentDB-> name returned malloc / calloc / realloc?
0
source

All Articles