Why does the crypt() function not have a memory leak?
Asked Answered
E

2

5

From crypt(3) - Linux man page:

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

Return Value: A pointer to the encrypted password is returned. On error, NULL is returned.

Since the return value is unknown unless key and salt is given, this should be dynamically allocated memory, but valgrind doesn't agree.

Elson answered 27/1, 2010 at 3:56 Comment(0)
S
9

From the man page:

The return value points to static data whose content is overwritten by each call.

So this means it's not dynamically allocated - it's a single static allocation (just like a global variable).

Snapper answered 27/1, 2010 at 3:59 Comment(0)
D
3

From the page you linked:

The returned value points to the encrypted password, a series of 13 printable ASCII characters (the first two characters represent the salt itself). The return value points to static data whose content is overwritten by each call.

Declaration answered 27/1, 2010 at 3:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.