File gdb-fix-use-of-invalid-pointer-in-remote-async-inferior-event-handler.patch of Package gdb

[gdb] Fix use of invalid pointer in remote_async_inferior_event_handler

As proposed by palves here (
https://sourceware.org/bugzilla/show_bug.cgi?id=26614#c20 ).

---
 gdb/remote.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index ba9e6d6e9b..556de6033f 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -14163,9 +14163,13 @@ remote_async_serial_handler (struct serial *scb, void *context)
 static void
 remote_async_inferior_event_handler (gdb_client_data data)
 {
+  remote_target *remote = (remote_target *) data;
+  /* Hold a strong reference to the remote target while handling an
+     event, since that could result in closing the connection.  */
+  auto remote_ref = target_ops_ref::new_reference (remote);
+
   inferior_event_handler (INF_REG_EVENT);
 
-  remote_target *remote = (remote_target *) data;
   remote_state *rs = remote->get_remote_state ();
 
   /* inferior_event_handler may have consumed an event pending on the
openSUSE Build Service is sponsored by