From 072f88f4d42e87c992cf420cfb98ae8cce54c177 Mon Sep 17 00:00:00 2001 From: Alex White Date: Wed, 9 Mar 2022 12:39:02 -0600 Subject: rtemstoolkit/rld-path.cpp: Fix double free --- rtemstoolkit/rld-path.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'rtemstoolkit') diff --git a/rtemstoolkit/rld-path.cpp b/rtemstoolkit/rld-path.cpp index 35af055..61c954d 100644 --- a/rtemstoolkit/rld-path.cpp +++ b/rtemstoolkit/rld-path.cpp @@ -109,23 +109,13 @@ namespace rld } else { - char* buf = 0; - try + std::vector buf (32 * 1024); + if (!::getcwd (buf.data(), buf.size())) { - buf = new char[32 * 1024]; - if (!::getcwd (buf, 32 * 1024)) - { - delete [] buf; - throw rld::error (::strerror (errno), "get current working directory"); - } - path_join (buf, path, apath); - delete [] buf; - } - catch (...) - { - delete [] buf; - throw; + throw rld::error (::strerror (errno), "get current working directory"); } + std::string cwd (buf.data()); + path_join (cwd, path, apath); } strings ps; -- cgit v1.2.3