...
In this example, the memory referred to by x
may be freed multiple times. if freed twice: once error_condition
is true , then x
is freed, and then freed again further along in again at the end of the code.
Code Block |
---|
*x = malloc (number * sizeof(int)); if (x == NULL) { /* Handle Allocation Error */ } if (error_conditon == 1) { /* Handle Error Condition*/ free(x); } /* ... */ free(x); |
...
Only free a pointer to dynamic memory referred to by x once. This For this example this can be accomplished in this example by removing the call to free()
in the section of code executed when error_condition
is true.
...