Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49387 - sandbox/SOC/2006/process/trunk/boost/process/detail
From: jmmv84_at_[hidden]
Date: 2008-10-19 09:54:29


Author: jmmv
Date: 2008-10-19 09:54:28 EDT (Sun, 19 Oct 2008)
New Revision: 49387
URL: http://svn.boost.org/trac/boost/changeset/49387

Log:
Avoid using strdup so that we can keep track of which specific memory
allocator was used and thus can free the memory appropriately. We were
using delete [] before, but strdup probably does a simple malloc.
Caught by valgrind in Linux.

Text files modified:
   sandbox/SOC/2006/process/trunk/boost/process/detail/posix_ops.hpp | 11 ++++++++---
   1 files changed, 8 insertions(+), 3 deletions(-)

Modified: sandbox/SOC/2006/process/trunk/boost/process/detail/posix_ops.hpp
==============================================================================
--- sandbox/SOC/2006/process/trunk/boost/process/detail/posix_ops.hpp (original)
+++ sandbox/SOC/2006/process/trunk/boost/process/detail/posix_ops.hpp 2008-10-19 09:54:28 EDT (Sun, 19 Oct 2008)
@@ -1,7 +1,7 @@
 //
 // Boost.Process
 //
-// Copyright (c) 2006 Julio M. Merino Vidal.
+// Copyright (c) 2006, 2008 Julio M. Merino Vidal.
 //
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
@@ -80,8 +80,13 @@
     typename Arguments::size_type i = 0;
     for (typename Arguments::const_iterator iter = args.begin();
          iter != args.end(); iter++) {
- argv[i] = ::strdup((*iter).c_str());
- i++;
+ const std::string& arg = *iter;
+
+ char* cstr = new char[arg.length() + 1];
+ std::strncpy(cstr, arg.c_str(), arg.length());
+ cstr[arg.length()] = '\0';
+
+ argv[i++] = cstr;
     }
     argv[nargs] = NULL;
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk