I'm using libssh2 to do some automated file transfers, and there's a
memory leak that's causing me some grief.
This is the code I'm running (error checks removed for brevity):
LIBSSH2_SESSION* ssh_session = libssh2_session_init();
int sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(22);
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
connect(sock, (struct sockaddr*)&addr, sizeof(addr));
libssh2_session_startup(ssh_session, sock);
libssh2_userauth_password(ssh_session, USERNAME, PASSWORD);
LIBSSH2_SFTP* sftp_session = libssh2_sftp_init(ssh_session);
libssh2_sftp_shutdown(sftp_session);
libssh2_session_disconnect(ssh_session, "File transfer complete");
libssh2_session_free(ssh_session);
close(sock);
Valgrind is reporting the following leaks:
==7236== HEAP SUMMARY:
==7236== in use at exit: 2,376 bytes in 40 blocks
==7236== total heap usage: 265 allocs, 225 frees, 91,929 bytes allocated
==7236==
==7236== 20 bytes in 1 blocks are definitely lost in loss record 1 of 7
==7236== at 0x4024C1C: malloc (vg_replace_malloc.c:195)
==7236== by 0x41A850F: _gcry_private_malloc (stdmem.c:108)
==7236== by 0x41A4747: do_malloc (global.c:737)
==7236== by 0x41A493C: _gcry_malloc (global.c:759)
==7236== by 0x41A499D: _gcry_xmalloc (global.c:903)
==7236== by 0x41F1A18: _gcry_mpi_alloc (mpiutil.c:52)
==7236== by 0x41A357C: gcry_mpi_new (visibility.c:243)
==7236== by 0x403B0CB:
kex_method_diffie_hellman_group14_sha1_key_exchange (kex.c:755)
==7236== by 0x403B259: libssh2_kex_exchange (kex.c:1746)
==7236== by 0x404392E: libssh2_session_startup (session.c:601)
==7236== by 0x80488D8: main (main.c:22)
==7236==
==7236== 20 bytes in 1 blocks are definitely lost in loss record 2 of 7
==7236== at 0x4024C1C: malloc (vg_replace_malloc.c:195)
==7236== by 0x41A850F: _gcry_private_malloc (stdmem.c:108)
==7236== by 0x41A4747: do_malloc (global.c:737)
==7236== by 0x41A493C: _gcry_malloc (global.c:759)
==7236== by 0x41A499D: _gcry_xmalloc (global.c:903)
==7236== by 0x41F1A18: _gcry_mpi_alloc (mpiutil.c:52)
==7236== by 0x41A357C: gcry_mpi_new (visibility.c:243)
==7236== by 0x4039308: diffie_hellman_sha1 (kex.c:98)
==7236== by 0x403B075:
kex_method_diffie_hellman_group14_sha1_key_exchange (kex.c:768)
==7236== by 0x403B259: libssh2_kex_exchange (kex.c:1746)
==7236== by 0x404392E: libssh2_session_startup (session.c:601)
==7236== by 0x80488D8: main (main.c:22)
==7236==
==7236== LEAK SUMMARY:
==7236== definitely lost: 40 bytes in 2 blocks
==7236== indirectly lost: 0 bytes in 0 blocks
==7236== possibly lost: 0 bytes in 0 blocks
==7236== still reachable: 2,336 bytes in 38 blocks
==7236== suppressed: 0 bytes in 0 blocks
==7236== Reachable blocks (those to which a pointer was found) are not
shown.
==7236== To see them, rerun with: --leak-check=full --show-reachable=yes
Is there another method I should be calling to free whatever
libssh2_session_startup is allocating?
Thanks,
--Joseph
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-03-25