> Is something wrong with that approach?

Depends on what you mean by wrong. But it keeps too much memory tied up. You see, the memory in `rettv->vval.v_string` is always `MAXPATHL` in your code. This might not be necessary, the actual path length might be much shorter.

My version is also shorter, and saves a `free`.