Edit: This is not a duplicate. The 'duplicate' post is about setting free'd memory to zero, this one is only about what happens with the variable! Please read the posts before flagging them or at least show in how far this is a duplicate.
Given a struct like
typedef struct simple {
int variable;
} Simple;
I usually delete such struct by using a function
void delete_simple(Simple *simple) {
if (simple) {
free(simple);
}
}
and use it like
delete_simple(mySimple)
But I recently figured the pointer to mySimple
would still remain non null, so I thought this might be a better approach:
Simple *destroy_simple(Simple *simple) {
if (simple) {
free(simple);
}
return 0;
}
and use it like
mySimple = delete_simple(mySimple)
Is this a better or worse way?