Bug 61851 - gnutls + neon: memory leak
Summary: gnutls + neon: memory leak
Status: RESOLVED FIXED
Alias: None
Product: SyncEvolution
Classification: Unclassified
Component: SyncEvolution (show other bugs)
Version: 1.3.99.3
Hardware: Other All
: medium normal
Assignee: Patrick Ohly
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-05 12:48 UTC by Patrick Ohly
Modified: 2014-07-15 08:55 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Patrick Ohly 2013-03-05 12:48:09 UTC
Started to appear after switching testing-amd64 apple caldav testing to https.
Need to investigate, going to suppress it for now in sys.supp.

# ==4782== 2,048 bytes in 1 blocks are definitely lost in loss record 2,395 of 2,503
# ==4782==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
# ==4782==    by 0x4C28D6F: realloc (vg_replace_malloc.c:632)
# ==4782==    by 0x10955415: ??? (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.22.4)
# ==4782==    by 0x109480DD: ??? (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.22.4)
# ==4782==    by 0x10944048: gnutls_session_get_data2 (in /usr/lib/x86_64-linux-gnu/libgnutls.so.26.22.4)
# ==4782==    by 0x6E4D666: ne_sock_connect_ssl (in /usr/lib/libneon-gnutls.so.27.2.6)
# ==4782==    by 0x6E572DE: ??? (in /usr/lib/libneon-gnutls.so.27.2.6)
# ==4782==    by 0x6E454F9: ??? (in /usr/lib/libneon-gnutls.so.27.2.6)
# ==4782==    by 0x6E45D1B: ne_begin_request (in /usr/lib/libneon-gnutls.so.27.2.6)
# ==4782==    by 0x6E453AC: ne_request_dispatch (in /usr/lib/libneon-gnutls.so.27.2.6)
# ==4782==    by 0x6E52BCC: ??? (in /usr/lib/libneon-gnutls.so.27.2.6)
# ==4782==    by 0x8ECB01: SyncEvo::Neon::Session::propfindURI(std::string const&, int, ne_propname const*, boost::function<void ()(SyncEvo::Neon::URI const&, ne_prop_result_set_s const*)> const&, SyncEvo::Timespec const&) (NeonCXX.cpp:426)
# ==4782==    by 0x8ECE4E: SyncEvo::Neon::Session::propfindProp(std::string const&, int, ne_propname const*, boost::function<void ()(SyncEvo::Neon::URI const&, ne_propname const*, char const*, ne_status const*)> const&, SyncEvo::Timespec const&) (NeonCXX.cpp:461)
# ==4782==    by 0x8E1539: SyncEvo::WebDAVSource::databaseRevision() (WebDAVSource.cpp:1332)
# ==4782==    by 0x8CF30C: SyncEvo::CalDAVSource::subDatabaseRevision() (CalDAVSource.h:37)
# ==4782==    by 0xA56FCC: SyncEvo::MapSyncSource::endSync(bool) (MapSyncSource.cpp:252)
# ==4782==    by 0x86FCEB: SyncEvo::TestingSyncSourcePtr::stopAccess() (ClientTest.cpp:349)
# ==4782==    by 0x870424: SyncEvo::TestingSyncSourcePtr::reset(SyncEvo::TestingSyncSource*, SyncEvo::TestingSyncSourcePtr::Flags) (ClientTest.cpp:294)
# ==4782==    by 0x7A3188: SyncEvo::LocalTests::testImport() (ClientTest.cpp:1473)
# ==4782==    by 0x7546B50: CppUnit::TestCaseMethodFunctor::operator()() const (in /usr/lib/libcppunit-1.12.so.1.0.0)
# ==4782==    by 0x753CBB4: CppUnit::DefaultProtector::protect(CppUnit::Functor const&, CppUnit::ProtectorContext const&) (in /usr/lib/libcppunit-1.12.so.1.0.0)
# ==4782==    by 0x7543B71: CppUnit::ProtectorChain::protect(CppUnit::Functor const&, CppUnit::ProtectorContext const&) (in /usr/lib/libcppunit-1.12.so.1.0.0)
# ==4782==    by 0x754C6F4: CppUnit::TestResult::protect(CppUnit::Functor const&, CppUnit::Test*, std::string const&) (in /usr/lib/libcppunit-1.12.so.1.0.0)
# ==4782==    by 0x754676E: CppUnit::TestCase::run(CppUnit::TestResult*) (in /usr/lib/libcppunit-1.12.so.1.0.0)
# ==4782==    by 0x754C679: CppUnit::TestResult::runTest(CppUnit::Test*) (in /usr/lib/libcppunit-1.12.so.1.0.0)
# ==4782==    by 0x754EB38: CppUnit::TestRunner::run(CppUnit::TestResult&, std::string const&) (in /usr/lib/libcppunit-1.12.so.1.0.0)
# ==4782==    by 0x7550DA5: CppUnit::TextTestRunner::run(std::string, bool, bool, bool) (in /usr/lib/libcppunit-1.12.so.1.0.0)
# ==4782==    by 0x6B921A: main (client-test-main.cpp:349)
Comment 1 Patrick Ohly 2014-07-14 14:27:57 UTC
From:	Werner Baumann <werner.baumann@onlinehome.de>
To:	neon@lists.manyfish.co.uk
Subject:	Memory leak when using GnuTLS
Date:	Sat, 24 May 2014 17:39:17 +0200

Hello,

a user of davfs2 reported ever growing use of real memory. A test
showed that this only happens when Neon is compiled against GnuTLS but
not when OpenSSL is used.

For example: when I create 10000 files I will get:
Neon with OpenSSL: about 5 MB of real memory (expected usage by davfs2)
Neon with GnuTLS: about 30 MB of real memory (about 25 MB leaked).

This seems to be the same error as reported in 
http://lists.manyfish.co.uk/pipermail/neon/2013-January/001526.html

The error is in ne_gnutls.c around line 677, function
ne_ssl_context_destroy:

void ne_ssl_context_destroy(ne_ssl_context *ctx)
{
    gnutls_certificate_free_credentials(ctx->cred);
    if (ctx->cache.client.data) {
        ne_free(ctx->cache.client.data);
    } else if (ctx->cache.server.key.data) {
        gnutls_free(ctx->cache.server.key.data);
        gnutls_free(ctx->cache.server.data.data);
    }    
    ne_free(ctx);
}

It uses ne_free for data allocated by GnuTLS. It should use
gnutls_free. The memory leak disappears when I change it like this:

void ne_ssl_context_destroy(ne_ssl_context *ctx)
{
    gnutls_certificate_free_credentials(ctx->cred);
    if (ctx->cache.client.data) {
        gnutls_free(ctx->cache.client.data);
    } else if (ctx->cache.server.key.data) {
        gnutls_free(ctx->cache.server.key.data);
        gnutls_free(ctx->cache.server.data.data);
    }    
    ne_free(ctx);
}

I tested with Neon 0.29.5 but the code in the git repository is the
same.

Cheers
Werner
Comment 2 Patrick Ohly 2014-07-15 08:55:47 UTC
This really explains the leak. Fix for Tizen pending (https://review.tizen.org/gerrit/#/c/24486), needs to be fixed upstream and in distro by someone else. Does not affect SyncEvolution much, because the code runs in its own process which cleans up when terminating.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.