On Wed, 2014-02-26 at 18:33 +0100, Lukas Slebodnik wrote:
ehlo,
Reported by: cppcheck
void free_fun(struct info *info)
free(info->name);
free(info);
info = NULL;
^^^^^^^^^^^
Assignment to function parameter has no effect outside the function.
Patch is attached.
Although the assignment is useless I do not like the solution.
I think the solution is not to remove the assignment but to change the
function prototype to take a pointer to the pointer we want to free so
that at the end of the function we can assign NULL to the original
variable we have been called to free.
Otherwise the caller has a dangling pointer.
So the solution for me is:
void free_fun(struct info **_info) {
struct info *info = *_info;
free(info->name);
free(info);
*info = NULL;
}
Simo.
--
Simo Sorce * Red Hat, Inc * New York