From 69ec37b97234fc47e77b633e0969c2646d4f2e4a Mon Sep 17 00:00:00 2001
From: Costas Argyris <costas.argyris@gmail.com>
Date: Sat, 2 Dec 2023 20:52:07 +0000
Subject: [PATCH] driver: Fix memory leak.

Use std::vector instead of malloc'd pointer
to get automatic freeing of memory.

Result was verified by valgrind, which showed
one less loss record.

Signed-off-by: Costas Argyris <costas.argyris@gmail.com>
---
 gcc/gcc.cc | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 9f21ad9453e..2623ab3a855 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -29,6 +29,7 @@ compilation is specified by a string called a "spec".  */
 
 #define INCLUDE_STRING
 #include "config.h"
+#define INCLUDE_VECTOR
 #include "system.h"
 #include "coretypes.h"
 #include "multilib.h" /* before tm.h */
@@ -9534,7 +9535,7 @@ struct mdswitchstr
   int len;
 };
 
-static struct mdswitchstr *mdswitches;
+static std::vector<struct mdswitchstr> mdswitches;
 static int n_mdswitches;
 
 /* Check whether a particular argument was used.  The first time we
@@ -9753,7 +9754,7 @@ set_multilib_dir (void)
     {
       int i = 0;
 
-      mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches);
+      mdswitches.resize (n_mdswitches);
       for (start = multilib_defaults; *start != '\0'; start = end + 1)
 	{
 	  while (*start == ' ' || *start == '\t')
@@ -11366,7 +11367,7 @@ driver::finalize ()
   input_from_pipe = 0;
   suffix_subst = NULL;
 
-  mdswitches = NULL;
+  mdswitches.clear ();
   n_mdswitches = 0;
 
   used_arg.finalize ();
-- 
2.30.2

