public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] driver: Fix memory leak.
@ 2023-12-02 21:24 Costas Argyris
  2023-12-04 12:15 ` Jonathan Wakely
  0 siblings, 1 reply; 12+ messages in thread
From: Costas Argyris @ 2023-12-02 21:24 UTC (permalink / raw)
  To: gcc-patches, jwakely


[-- Attachment #1.1: Type: text/plain, Size: 224 bytes --]

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.

I think Jonathan is/was working on this transition
but on a larger scale.

[-- Attachment #2: 0001-driver-Fix-memory-leak.patch --]
[-- Type: application/octet-stream, Size: 1576 bytes --]

From cf444a8c5146629ac883da46f5f5300cd9f3d75e 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..63be4247f1d 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -47,6 +47,7 @@ compilation is specified by a string called a "spec".  */
 #include "opts-jobserver.h"
 #include "common/common-target.h"
 #include "gcc-urlifier.h"
+#include <vector>
 
 #ifndef MATH_LIBRARY
 #define MATH_LIBRARY "m"
@@ -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.reserve (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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-12-08 13:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-02 21:24 [PATCH] driver: Fix memory leak Costas Argyris
2023-12-04 12:15 ` Jonathan Wakely
2023-12-06 14:29   ` Costas Argyris
2023-12-06 14:39     ` Jakub Jelinek
2023-12-07 14:28       ` Costas Argyris
2023-12-07 14:42         ` Jakub Jelinek
2023-12-07 15:16           ` Costas Argyris
2023-12-07 15:42             ` Jakub Jelinek
2023-12-07 16:01               ` Costas Argyris
2023-12-07 16:04                 ` Jakub Jelinek
2023-12-08 12:18                   ` Costas Argyris
2023-12-08 13:16                     ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).