It's confusing if you're mallocing in one scope and freeing it in another one (foo is especially confusing, besides being a disaster ready to happen). But if you write bar() like this:
void bar() {
char *b = malloc(123);
foo(b);
free(b);
b = NULL;
}
it looks all right.Not that I'm advocating this kind of use. I have... mixed feelings about it. But I've seen it used and it doesn't have to be confusing.
Its primary merit is that it makes use-after-free cases immediately obvious, since they're going to trigger a segfault.
But there are better ways to achieve that.