[Boost-bugs] [Boost C++ Libraries] #3474: Memory leak due to exception safety issue

Subject: [Boost-bugs] [Boost C++ Libraries] #3474: Memory leak due to exception safety issue
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-09-21 23:47:15


#3474: Memory leak due to exception safety issue
--------------------------------------+-------------------------------------
 Reporter: lee@… | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: Boost 1.41.0 | Component: filesystem
  Version: Boost 1.40.0 | Severity: Problem
 Keywords: |
--------------------------------------+-------------------------------------
 The following code fragment form file 'libs/filesystem/src/exception.cpp'
 may leak memory if an exception is thrown while assigning 'lpMsgBuf' to
 'target':

 {{{
 void system_message(system_error_type sys_err_code, std::string& target)
 {
   LPVOID lpMsgBuf;
   ::FormatMessageA(
       FORMAT_MESSAGE_ALLOCATE_BUFFER |
       FORMAT_MESSAGE_FROM_SYSTEM |
       FORMAT_MESSAGE_IGNORE_INSERTS,
       NULL,
       sys_err_code,
       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
       (LPSTR) &lpMsgBuf,
       0,
       NULL
   );
   target += static_cast<LPCSTR>(lpMsgBuf);
   ::LocalFree( lpMsgBuf ); // free the buffer

   //...
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3474>
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-02-16 18:50:01 UTC