gcc 4.7.2 c89
Hello,
I have the following function:
void module_param_destroy(module_param_t *param)
{
param = NULL;
/* Stop the compiler from complaining */
APR_UNUSED(param);
}
And I am calling it like this:
module_param_destroy(module->call_param);
Would the parameter param be set to NULL. As I am passing in a local copy, I don’t think it is doing anything useful here.
Would it be better to do this:
void module_param_destroy(module_t *md)
{
md->param = NULL;
/* Stop the compiler from complaining */
APR_UNUSED(md->param);
}
And calling it like this:
module_param_destroy(md);
The structures have globally allocated memory from malloc.
Many thanks for any suggestions,
If param points to memory obtained from
malloc, then setting it toNULLis not enough to properly cleanup.There are two common ways to use
module_param_destroy:or
The main difference is that with the second variant, param gets set to a testable value to indicate it has been cleaned up. With the first variant, you have to remember yourself that the pointer passed to
module_param_destroyis unusable after the function has returned.You call them respectively as
and