4 ms·
If `foo` doesn't own `buf`, it should be declared `char * const` (or `char const * const`). If `foo` takes owner ship of `buf` (and is intended to free it), it
by btrask 11y ago
If `foo` doesn't own `buf`, it should be declared `char * const` (or `char const * const`). If `foo` takes owner ship of `buf` (and is intended to free it), it should take a pointer to the pointer to clear it for the caller. This is one way to write it:
void foo(char **const bufptr) {
...
free(*bufptr); *bufptr = NULL;
}
You can dereference `bufptr` at the top of the function to make the code more readable. This is how (almost) every object freeing function works in my project.