Fix undefined behavior in gdbserver

PR gdb/26742 points out some undefined behavior in gdbserver.  The bug
is that remove_thread does:

  free_one_thread (thread);
  if (current_thread == thread)
    current_thread = NULL;

However, the equality check is undefined, because "thread" has already
been freed.

This patch fixes the bug by moving the check earlier.

Tested on x86-64 Fedora 32.

2020-10-20  Tom Tromey  <tromey@adacore.com>

	PR gdb/26742:
	* inferiors.cc (remove_thread): Clear current_thread before
	freeing the thread.
This commit is contained in:
Tom Tromey 2020-10-20 10:28:58 -06:00
parent e0c45dedd9
commit a9b45cb776
2 changed files with 7 additions and 1 deletions

View file

@ -1,3 +1,9 @@
2020-10-20 Tom Tromey <tromey@adacore.com>
PR gdb/26742:
* inferiors.cc (remove_thread): Clear current_thread before
freeing the thread.
2020-10-13 Kamil Rytarowski <n54@gmx.com>x
* netbsd-low.cc (netbsd_tdesc): Remove.

View file

@ -103,9 +103,9 @@ remove_thread (struct thread_info *thread)
discard_queued_stop_replies (ptid_of (thread));
all_threads.remove (thread);
free_one_thread (thread);
if (current_thread == thread)
current_thread = NULL;
free_one_thread (thread);
}
void *