Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

crypt

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.

like image 436
Figo Avatar asked Jan 27 '10 03:01

Figo


1 Answers

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).

like image 50
caf Avatar answered Sep 17 '22 13:09

caf