Opened 10 years ago

Last modified 5 years ago

#6879 reopened Bugs

Memory leak using resolve() method from basic_resolver

Reported by: Tony Ho <Tony.Ho@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.63.0 Severity: Problem
Keywords: Cc:

Description

Every time I use the resolve(), memory goes up. I have checked the latest code, it looks like the resolve() in resolver_service.hpp never call freeaddrinfo() to free the memory 'address_info' allocated by getaddrinfo().

Change History (4)

comment:1 by viboes, 10 years ago

Component: Noneasio
Owner: set to chris_kohlhoff

comment:2 by chris_kohlhoff, 10 years ago

Resolution: worksforme
Status: newclosed

The freeaddrinfo() function is called automatically by the auto_addrinfo class. Please reopen this ticket if you can supply a test program that reproduces the problem, as well as details on the target platform and compiler.

comment:3 by mike.gresens@…, 5 years ago

Resolution: worksforme
Status: closedreopened
Version: Boost 1.49.0Boost 1.63.0

Given the following code:

#include <boost/asio.hpp>
#include <iostream>

void test()
{
    boost::asio::io_service service;
    boost::asio::ip::tcp::resolver resolver{service};
    boost::asio::ip::tcp::socket socket{service};
    boost::asio::ip::tcp::resolver::query query{"hessian.caucho.com", "http"};
    boost::asio::connect(socket, resolver.resolve(query));
}

int main()
{
    try
    {
        test();
    }
    catch (std::exception const& exception)
    {
        std::cerr << "error: " << exception.what() << std::endl;
    }
    return 0;
}

And running the binary with valgrind:

valgrind --leak-check=full bin/gcc-7/debug/hessian-foo

Produces these errors/warnings:

==6795== Memcheck, a memory error detector
==6795== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==6795== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==6795== Command: bin/gcc-7/debug/hessian-foo
==6795== 
==6795== 
==6795== HEAP SUMMARY:
==6795==     in use at exit: 5,741 bytes in 7 blocks
==6795==   total heap usage: 176 allocs, 169 frees, 128,625 bytes allocated
==6795== 
==6795== 4,096 bytes in 1 blocks are definitely lost in loss record 7 of 7
==6795==    at 0x4C2DB2F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6795==    by 0x406B991: ???
==6795==    by 0x40698DB: ???
==6795==    by 0x408E060: ???
==6795==    by 0x406ADDC: ???
==6795==    by 0x58E916E: gaih_inet.constprop.5 (getaddrinfo.c:848)
==6795==    by 0x58EB447: getaddrinfo (getaddrinfo.c:2391)
==6795==    by 0x111D1F: boost::asio::detail::socket_ops::getaddrinfo(char const*, char const*, addrinfo const&, addrinfo**, boost::system::error_code&) (socket_ops.ipp:3240)
==6795==    by 0x116255: boost::asio::detail::resolver_service<boost::asio::ip::tcp>::resolve(std::shared_ptr<void>&, boost::asio::ip::basic_resolver_query<boost::asio::ip::tcp> const&, boost::system::error_code&) (resolver_service.hpp:64)
==6795==    by 0x115425: boost::asio::ip::resolver_service<boost::asio::ip::tcp>::resolve(std::shared_ptr<void>&, boost::asio::ip::basic_resolver_query<boost::asio::ip::tcp> const&, boost::system::error_code&) (resolver_service.hpp:113)
==6795==    by 0x114627: boost::asio::ip::basic_resolver<boost::asio::ip::tcp, boost::asio::ip::resolver_service<boost::asio::ip::tcp> >::resolve(boost::asio::ip::basic_resolver_query<boost::asio::ip::tcp> const&) (basic_resolver.hpp:102)
==6795==    by 0x10CBCC: test() (foo.cpp:17)
==6795== 
==6795== LEAK SUMMARY:
==6795==    definitely lost: 4,096 bytes in 1 blocks
==6795==    indirectly lost: 0 bytes in 0 blocks
==6795==      possibly lost: 0 bytes in 0 blocks
==6795==    still reachable: 1,645 bytes in 6 blocks
==6795==         suppressed: 0 bytes in 0 blocks
==6795== Reachable blocks (those to which a pointer was found) are not shown.
==6795== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6795== 
==6795== For counts of detected and suppressed errors, rerun with: -v
==6795== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

System:

Linux workstation 4.10.0-22-generic #24-Ubuntu SMP Mon May 22 17:43:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Compilers:

g++ (Ubuntu 7-20170407-0ubuntu2) 7.0.1 20170407 (experimental) [trunk revision 246759]
g++ (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
clang version 4.0.0-1ubuntu1 (tags/RELEASE_400/rc1)

comment:4 by anonymous, 5 years ago

same here

Note: See TracTickets for help on using tickets.