* [PATCH] Use std::string for 'psargs'.
@ 2020-03-05 23:07 John Baldwin
2020-03-05 23:15 ` Simon Marchi
0 siblings, 1 reply; 3+ messages in thread
From: John Baldwin @ 2020-03-05 23:07 UTC (permalink / raw)
To: gdb-patches
fbsd_make_corefile_notes leaked the memory for psargs previously.
gdb/ChangeLog:
* fbsd-tdep.c (fbsd_make_corefile_notes): Use std::string for
psargs.
---
gdb/ChangeLog | 5 +++++
gdb/fbsd-tdep.c | 10 +++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d8c44d80e4..ee0d10d8c9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-03-05 John Baldwin <jhb@FreeBSD.org>
+
+ * fbsd-tdep.c (fbsd_make_corefile_notes): Use std::string for
+ psargs.
+
2020-03-05 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* .gitattributes: New file.
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index bc1b5afd02..ffffb18700 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -725,14 +725,14 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
if (get_exec_file (0))
{
const char *fname = lbasename (get_exec_file (0));
- char *psargs = xstrdup (fname);
+ std::string psargs = fname;
- if (get_inferior_args ())
- psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
- (char *) NULL);
+ const char *infargs = get_inferior_args ();
+ if (infargs != NULL)
+ psargs = psargs + " " + infargs;
note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
- fname, psargs);
+ fname, psargs.c_str ());
}
/* Thread register information. */
--
2.23.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Use std::string for 'psargs'.
2020-03-05 23:07 [PATCH] Use std::string for 'psargs' John Baldwin
@ 2020-03-05 23:15 ` Simon Marchi
2020-03-05 23:58 ` John Baldwin
0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2020-03-05 23:15 UTC (permalink / raw)
To: John Baldwin, gdb-patches
On 2020-03-05 6:06 p.m., John Baldwin wrote:
> diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
> index bc1b5afd02..ffffb18700 100644
> --- a/gdb/fbsd-tdep.c
> +++ b/gdb/fbsd-tdep.c
> @@ -725,14 +725,14 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
> if (get_exec_file (0))
> {
> const char *fname = lbasename (get_exec_file (0));
> - char *psargs = xstrdup (fname);
> + std::string psargs = fname;
>
> - if (get_inferior_args ())
> - psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
> - (char *) NULL);
> + const char *infargs = get_inferior_args ();
> + if (infargs != NULL)
> + psargs = psargs + " " + infargs;
Doesn't really matter, but you could use += here.
LGTM in any case, thanks!
Simon
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Use std::string for 'psargs'.
2020-03-05 23:15 ` Simon Marchi
@ 2020-03-05 23:58 ` John Baldwin
0 siblings, 0 replies; 3+ messages in thread
From: John Baldwin @ 2020-03-05 23:58 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 3/5/20 3:15 PM, Simon Marchi wrote:
> On 2020-03-05 6:06 p.m., John Baldwin wrote:
>> diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
>> index bc1b5afd02..ffffb18700 100644
>> --- a/gdb/fbsd-tdep.c
>> +++ b/gdb/fbsd-tdep.c
>> @@ -725,14 +725,14 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
>> if (get_exec_file (0))
>> {
>> const char *fname = lbasename (get_exec_file (0));
>> - char *psargs = xstrdup (fname);
>> + std::string psargs = fname;
>>
>> - if (get_inferior_args ())
>> - psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
>> - (char *) NULL);
>> + const char *infargs = get_inferior_args ();
>> + if (infargs != NULL)
>> + psargs = psargs + " " + infargs;
>
> Doesn't really matter, but you could use += here.
I almost did, but based this on the similar code in linux-tdep.c and went
with consistency.
--
John Baldwin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-05 23:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05 23:07 [PATCH] Use std::string for 'psargs' John Baldwin
2020-03-05 23:15 ` Simon Marchi
2020-03-05 23:58 ` John Baldwin
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).