...
Code Block | ||
---|---|---|
| ||
size_t num_elem = /* some initial value */; int error_condition = 0; int *x = (int *)malloc(num_elem * sizeof(int)); if (x == NULL) { /* handle allocation error */ } /* ... */ if (error_condition == 1) { /* handle error condition*/ free(x); x = NULL; } /* ... */ free(x); x = NULL; |
Compliant Solution
In this compliant solution, the free a referenced by x
is only freed once. This is accomplished by eliminating the call to free()
when error_condition
is equal to 1.
...