That whole block confuses me. This makes it look like we expect the caller to have an uninitialized pointer and then initialize it? That whole block doesn't make much sense to me.  Wouldn't it be better if we'd report an error here instead of freeing the caller's memory behind their back?