From f404573e4f8d22f0f1f87eee4f08fa132b15a9aa Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Wed, 2 Sep 2020 19:24:05 +0200 Subject: [PATCH] Avoid double free in startup_inferior 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 ecf8e37f58b..80c77c2e388 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2020-09-10 Kamil Rytarowski + + * fork-inferior.c (startup_inferior): Avoid double free. + 2020-09-10 Kamil Rytarowski * netbsd-nat.h (netbsd_nat::qxfer_siginfo): Add. diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c index 1185ef8998b..7ba0126871d 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); + /* Free the exec'ed pathname, but only if this isn't the + waitstatus we are returning to the caller. */ + if (pending_execs != 1) + xfree (ws.value.execd_pathname); resume_signal = GDB_SIGNAL_TRAP; switch_to_thread (proc_target, event_ptid); break; -- 2.30.2