From what I can see, your primary case for a return in the middle of a function is in case of an error. Check all parameters for errors before processing anything. and maybe a:
Code: Select all
if (valid) { ... }
Or better, you can have an inline function which will process your allocated variables:
Code: Select all
void foo(...)
{
void* buffer = NULL;
buffer = malloc(1337);
process(buffer);
free(buffer);
}
On a side note, you can remove the if (x != NULL) checks before free calling free(x). The standard dictates that free performs no operation if x is null.
The free function causes the space pointed to by ptr to be deallocated, that is, made
available for further allocation. If ptr is a null pointer, no action occurs. Otherwise, if
the argument does not match a pointer earlier returned by a memory management
function, or if the space has been deallocated by a call to free or realloc, the
behavior is undefined.