[SSSD] [PATCH] Remove useless assignment to function parameter
Simo Sorce
simo at redhat.com
Wed Feb 26 18:00:41 UTC 2014
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
More information about the sssd-devel
mailing list