Should I free/delete char* returned by getenv()? Should I free/delete char* returned by getenv()? c c

Should I free/delete char* returned by getenv()?


No you shouldn't. Standard 7.20.4.5 says :

The getenv function returns a pointer to a string associated with the matched list member. The string pointed to shall not be modified by the program, but may be overwritten by a subsequent call to the getenv function.

I believe deletion is covered by the text in bold.


You should not free it. This is a snippet from the man page:

As typically implemented, getenv() returns a pointer to a string within the environment list. The caller must take care not to modify this string, since that would change the environment of the process.

Don't touch it !


No. You don't control its storage. Typically, it's a pointer to a static array that is reused multiple times. For this reason, you should copy it if you plan to store it for later use (you should ensure this copy is freed properly).

Unless the documentation explicitly says you may free a pointer, you should not.