[Bug 1419620] [NEW] ~76 kB memory leak per client instance

Michi Henning michi.henning at canonical.com
Mon Feb 9 06:19:49 UTC 2015


Public bug reported:

net-cpp leaks memory for each http client instance. To reproduce:

#include <core/net/http/client.h>

int main()
{
    core::net::http::make_client();
}

==22658== 
==22658== HEAP SUMMARY:
==22658==     in use at exit: 78,572 bytes in 1,040 blocks
==22658==   total heap usage: 13,600 allocs, 12,560 frees, 446,676 bytes allocated
==22658== 
...
==22658== LEAK SUMMARY:
==22658==    definitely lost: 512 bytes in 1 blocks
==22658==    indirectly lost: 77,996 bytes in 1,037 blocks
==22658==      possibly lost: 0 bytes in 0 blocks
==22658==    still reachable: 64 bytes in 2 blocks

Dropping a bit of trace into the library shows that the Handle::Private
struct is never destroyed:

multi::Handle::Private::Private()
    : handle(multi::native::init()),
      keep_alive(dispatcher),
      timeout(dispatcher)
{
    std::cerr << "initializing" << std::endl;
}

multi::Handle::Private::~Private()
{
    std::cerr << "cleaning up" << std::endl;
    multi::native::cleanup(handle);
}

This prints "initializing", but doesn't print "cleaning up".

Checking the use count of the multi::Handle member of http::Client in
the Client destructor shows that the use count is 2 when the Client goes
out of scope.

The leak is caused here:

multi::Handle::Handle() : d(new Private())
{
    auto holder = new Holder<Private>{d};

    set_option(Option::socket_function, Private::socket_callback);
    set_option(Option::socket_data, holder);
    set_option(Option::timer_function, Private::timer_callback);
    set_option(Option::timer_data, holder);

    set_option(Option::pipelining, easy::enable);
}

The Holder that is allocated here is never deleted and points at the
Private a second time.

** Affects: net-cpp
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Phablet Team, which is subscribed to net-cpp.
Matching subscriptions: net-cpp-bugs
https://bugs.launchpad.net/bugs/1419620

Title:
  ~76 kB memory leak per client instance

To manage notifications about this bug go to:
https://bugs.launchpad.net/net-cpp/+bug/1419620/+subscriptions



More information about the Ubuntu-reviews mailing list