Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In C the way to solve this is to look at the man page for the function and see what they say about memory allocation. There is no magic involved.


Documentation solves just one problem: to free or not to free.

But there are performance, security and other issues.

What if it is significantly more performant for getenv() (or whatever) to fetch needed data using alloca (on stack, with fallback to heap/malloc)?

Returning naked pointer is far from being flexible really.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: