gpt4 book ai didi

ubuntu - 使用 libssh 时的内存泄漏

转载 作者:行者123 更新时间:2023-12-04 18:56:26 24 4
gpt4 key购买 nike

我正在尝试在我的应用程序中使用 libssh,但我不断收到内存泄漏。我正在尝试的最简单的代码是:

#include <libssh/libssh.h>
#define SSH_NO_CPP_EXCEPTIONS
assert(0 == ssh_init());

ssh_session m_session;
assert(m_session = ssh_new());

int port = 22;
assert(0 == ssh_options_set(m_session, SSH_OPTIONS_HOST, "user1@computer1"));
assert(0 == ssh_options_set(m_session, SSH_OPTIONS_PORT, &port));
assert(SSH_OK == ssh_connect(m_session));

ssh_disconnect(m_session);
ssh_free(m_session);
assert(0 == ssh_finalize());

按预期工作,但 Valgrind 提示泄漏(好像所有由 ssh_connect 分配的内存都没有被释放):
==17385== HEAP SUMMARY:
==17385== in use at exit: 300 bytes in 11 blocks
==17385== total heap usage: 2,008 allocs, 1,997 frees, 5,529,273 bytes allocated
==17385==
==17385== 300 (60 direct, 240 indirect) bytes in 1 blocks are definitely lost in loss record 11 of 11
==17385== at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==17385== by 0x60ED594: nss_parse_service_list (nsswitch.c:678)
==17385== by 0x60EE055: __nss_database_lookup (nsswitch.c:175)
==17385== by 0x94AC623: ???
==17385== by 0x60A6BFC: getpwuid_r@@GLIBC_2.2.5 (getXXbyYY_r.c:256)
==17385== by 0x58B25F7: ssh_get_user_home_dir (misc.c:216)
==17385== by 0x58B2F42: ssh_path_expand_tilde (misc.c:673)
==17385== by 0x58B3F57: ssh_options_set (options.c:457)
==17385== by 0x58B4702: ssh_options_apply (options.c:915)
==17385== by 0x58A72CD: ssh_connect (client.c:652)
==17385== by 0x421896: sshTest() (main.cpp:589)
==17385== by 0x418F67: main (main.cpp:51)
==17385==
==17385== LEAK SUMMARY:
==17385== definitely lost: 60 bytes in 1 blocks
==17385== indirectly lost: 240 bytes in 10 blocks
==17385== possibly lost: 0 bytes in 0 blocks
==17385== still reachable: 0 bytes in 0 blocks
==17385== suppressed: 0 bytes in 0 blocks

我在用:
  • Ubuntu 12.04 x64 LTS
  • libssh 版本 0.5.2-1ubuntu0.12.04.1(目前最新可用)
  • g++/gcc 版本 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  • valgrind-3.7.0

  • 我究竟做错了什么?任何帮助将不胜感激。

    最佳答案

    你没有做错任何事。 libssh 中没有内存泄漏,这是您的 libc :)

    关于ubuntu - 使用 libssh 时的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13818105/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com