[rtems-tools commit] rtemstoolkit/rld-path.cpp: Fix double free

Joel Sherrill joel at rtems.org
Wed Mar 9 21:57:38 UTC 2022


Module:    rtems-tools
Branch:    master
Commit:    072f88f4d42e87c992cf420cfb98ae8cce54c177
Changeset: http://git.rtems.org/rtems-tools/commit/?id=072f88f4d42e87c992cf420cfb98ae8cce54c177

Author:    Alex White <alex.white at oarcorp.com>
Date:      Wed Mar  9 12:39:02 2022 -0600

rtemstoolkit/rld-path.cpp: Fix double free

---

 rtemstoolkit/rld-path.cpp | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

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<char> 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;



More information about the vc mailing list