Why doesn't crypt () function have a memory leak?

From crypt (3) - Linux man page :

char *crypt(const char *key, const char *salt); 

Return value : Returns a pointer to the encrypted password. On error, NULL returned.

Since the return value is unknown, if the key and salt values ​​are not specified, this should be dynamically allocated memory, but valgrind does not agree.

+4
source share
2 answers

On the man page:

The return value indicates static data whose contents are overwritten by each call.

So, this means that it is not dynamically allocated - it is one static distribution (like a global variable).

+8
source

On the page you indicated:

The return value indicates an encrypted password, a series of 13 printed ASCII characters (the first two characters are salt). The return value indicates static data whose contents are overwritten by each call.

+3
source

Source: https://habr.com/ru/post/1299510/


All Articles