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

发布于 2024-08-19 03:59:36 字数 310 浏览 3 评论 0原文

来自 crypt(3) - Linux 手册页

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

返回值: 返回指向加密密码的指针。出错时,返回NULL

由于返回值是未知的,除非给出 key 和 salt,所以这应该是动态分配的内存,但 valgrind 不同意。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫以 2024-08-26 03:59:36

从手册页:

返回值指向静态数据
其内容会被每次调用覆盖。

所以这意味着它不是动态分配的 - 它是单个静态分配(就像全局变量一样)。

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

回梦 2024-08-26 03:59:36

从您链接的页面:

返回值指向加密密码,一系列 13 个可打印 ASCII 字符(前两个字符代表盐本身)。返回值指向静态数据,其内容会被每次调用覆盖。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文