Memory leak when using GnuTLS

Werner Baumann werner.baumann at onlinehome.de
Sat May 24 11:39:17 EDT 2014


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



More information about the neon mailing list