[PATCH 08/10] Avoid double free in startup_inferior

Kamil Rytarowski
2020-09-02T18:00:12Z

Do not free the last execd pathname as it will be used in
prepare_resume_reply(), after attaching a client side.

gdb/ChangeLog:

* fork-inferior.c (startup_inferior): Avoid double free.
---
gdb/ChangeLog | 4 ++++
gdb/nat/fork-inferior.c | 5 ++++-
2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1dcf5d0ca81..c57504a6ceb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2020-08-13 Kamil Rytarowski <n54@gmx.com>
+
+ * fork-inferior.c (startup_inferior): Avoid double free.
+
2020-08-13 Kamil Rytarowski <n54@gmx.com>

* netbsd-nat.h (netbsd_nat::qxfer_siginfo): Add.
diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c
index 1185ef8998b..94ab0b9cbc2 100644
--- a/gdb/nat/fork-inferior.c
+++ b/gdb/nat/fork-inferior.c
@@ -526,7 +526,10 @@ startup_inferior (process_stratum_target *proc_target, pid_t pid, int ntraps,

case TARGET_WAITKIND_EXECD:
/* Handle EXEC signals as if they were SIGTRAP signals. */
- xfree (ws.value.execd_pathname);
+ /* Do not free the last execd pathname as it will be used in
+ prepare_resume_reply(), after attaching a client side. */
+ if (pending_execs != 1)
+ xfree (ws.value.execd_pathname);
resume_signal = GDB_SIGNAL_TRAP;
switch_to_thread (proc_target, event_ptid);
break;
--
2.28.0