aboutsummaryrefslogtreecommitdiff
path: root/gdb/buildsym.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2022-04-07 08:06:50 -0400
committerSimon Marchi <simon.marchi@efficios.com>2022-04-12 14:13:10 -0400
commit71bc95ed2032567e2a7aebc3efe1c55a77abb7b2 (patch)
treedf72666a77b98bda029327e1acfc5b2366ebe766 /gdb/buildsym.c
parent30bf8e1ce4498467d62387b0d8a7009e3fbe2ab1 (diff)
downloadbinutils-71bc95ed2032567e2a7aebc3efe1c55a77abb7b2.zip
binutils-71bc95ed2032567e2a7aebc3efe1c55a77abb7b2.tar.gz
binutils-71bc95ed2032567e2a7aebc3efe1c55a77abb7b2.tar.bz2
gdb: allocate subfile with new
Allocate struct subfile with new, initialize its fields instead of memset-ing it to 0. Use a unique_ptr for the window after a subfile has been allocated but before it is linked in the buildsym_compunit's list of subfile (and therefore owned by the buildsym_compunit. I can't test the change in xcoffread.c, it's best-effort. I couldn't find where subfiles are freed in that file, I assume they were intentionally (or not) leaked. Change-Id: Ib3b6877de31b7e65bc466682f08dbf5840225f24
Diffstat (limited to 'gdb/buildsym.c')
-rw-r--r--gdb/buildsym.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 0df3551..aedc3c6 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -97,7 +97,7 @@ buildsym_compunit::~buildsym_compunit ()
nextsub = subfile->next;
xfree (subfile->name);
xfree (subfile->line_vector);
- xfree (subfile);
+ delete subfile;
}
struct pending *next, *next1;
@@ -504,13 +504,12 @@ void
buildsym_compunit::start_subfile (const char *name)
{
const char *subfile_dirname;
- struct subfile *subfile;
subfile_dirname = m_comp_dir.get ();
/* See if this subfile is already registered. */
- for (subfile = m_subfiles; subfile; subfile = subfile->next)
+ for (subfile *subfile = m_subfiles; subfile; subfile = subfile->next)
{
char *subfile_name;
@@ -537,13 +536,9 @@ buildsym_compunit::start_subfile (const char *name)
/* This subfile is not known. Add an entry for it. */
- subfile = XNEW (struct subfile);
- memset (subfile, 0, sizeof (struct subfile));
-
- subfile->next = m_subfiles;
- m_subfiles = subfile;
+ subfile_up subfile (new struct subfile);
- m_current_subfile = subfile;
+ m_current_subfile = subfile.get ();
subfile->name = xstrdup (name);
@@ -562,11 +557,8 @@ buildsym_compunit::start_subfile (const char *name)
source file. */
subfile->language = deduce_language_from_filename (subfile->name);
- if (subfile->language == language_unknown
- && subfile->next != NULL)
- {
- subfile->language = subfile->next->language;
- }
+ if (subfile->language == language_unknown && m_subfiles != nullptr)
+ subfile->language = m_subfiles->language;
/* If the filename of this subfile ends in .C, then change the
language of any pending subfiles from C to C++. We also accept
@@ -586,12 +578,14 @@ buildsym_compunit::start_subfile (const char *name)
/* And patch up this file if necessary. */
if (subfile->language == language_c
- && subfile->next != NULL
- && (subfile->next->language == language_cplus
- || subfile->next->language == language_fortran))
- {
- subfile->language = subfile->next->language;
- }
+ && m_subfiles != nullptr
+ && (m_subfiles->language == language_cplus
+ || m_subfiles->language == language_fortran))
+ subfile->language = m_subfiles->language;
+
+ /* Link this subfile at the front of the subfile list. */
+ subfile->next = m_subfiles;
+ m_subfiles = subfile.release ();
}
/* For stabs readers, the first N_SO symbol is assumed to be the
@@ -791,7 +785,8 @@ buildsym_compunit::watch_main_source_file_lossage ()
else
prev_mainsub_alias->next = mainsub_alias->next;
xfree (mainsub_alias->name);
- xfree (mainsub_alias);
+
+ delete mainsub_alias;
}
}
}