Re: [Boost-bugs] [Boost C++ Libraries] #6879: Memory leak using resolve() method from basic_resolver

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6879: Memory leak using resolve() method from basic_resolver
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-06-16 14:01:35


#6879: Memory leak using resolve() method from basic_resolver
----------------------------------+----------------------------
  Reporter: Tony Ho <Tony.Ho@…> | Owner: chris_kohlhoff
      Type: Bugs | Status: reopened
 Milestone: To Be Determined | Component: asio
   Version: Boost 1.63.0 | Severity: Problem
Resolution: | Keywords:
----------------------------------+----------------------------
Changes (by mike.gresens@…):

 * status: closed => reopened
 * version: Boost 1.49.0 => Boost 1.63.0
 * resolution: worksforme =>

Comment:

 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)
 }}}

--
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/6879#comment:3>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-06-16 14:05:34 UTC