简体   繁体   English

为什么crypt()函数没有内存泄漏?

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

From crypt(3) - Linux man page : 来自crypt(3) - Linux手册页

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

Return Value : A pointer to the encrypted password is returned. 返回值返回指向加密密码的指针。 On error, NULL is returned. 出错时,返回NULL

Since the return value is unknown unless key and salt is given, this should be dynamically allocated memory, but valgrind doesn't agree. 由于除非给出key和salt,否则返回值是未知的,这应该是动态分配的内存,但valgrind不同意。

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). 所以这意味着它不是动态分配的 - 它是一个静态分配(就像一个全局变量)。

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). 返回值指向加密密码,一系列13个可打印的ASCII字符(前两个字符代表盐本身)。 The return value points to static data whose content is overwritten by each call. 返回值指向静态数据,其内容被每次调用覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM