about summary refs log tree commit diff
path: root/sysdeps/mach/hurd/x86_64/tls.h
diff options
context:
space:
mode:
authorSergey Bugaev <bugaevc@gmail.com>2023-03-19 18:10:10 +0300
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-04-11 00:24:40 +0200
commitcd019ddd892e182277fadd6aedccc57fa3923c8d (patch)
treecfcc71948e40bd484e00e3105153ec305e6b19a8 /sysdeps/mach/hurd/x86_64/tls.h
parent747812349d42427c835aeac987aa67641d84f1ad (diff)
downloadglibc-cd019ddd892e182277fadd6aedccc57fa3923c8d.tar.gz
glibc-cd019ddd892e182277fadd6aedccc57fa3923c8d.tar.xz
glibc-cd019ddd892e182277fadd6aedccc57fa3923c8d.zip
hurd: Don't leak __hurd_reply_port0
Previously, once we set up TLS, we would implicitly switch from using
__hurd_reply_port0 to reply_port inside the TCB, leaving the former
unused. But we never deallocated it, so it got leaked.

Instead, migrate the port into the new TCB's reply_port slot. This
avoids both the port leak and an extra syscall to create a new reply
port for the TCB.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-Id: <20230319151017.531737-28-bugaevc@gmail.com>
Diffstat (limited to 'sysdeps/mach/hurd/x86_64/tls.h')
-rw-r--r--sysdeps/mach/hurd/x86_64/tls.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/sysdeps/mach/hurd/x86_64/tls.h b/sysdeps/mach/hurd/x86_64/tls.h
index da504d9c81..2b7135f635 100644
--- a/sysdeps/mach/hurd/x86_64/tls.h
+++ b/sysdeps/mach/hurd/x86_64/tls.h
@@ -177,13 +177,20 @@ _hurd_tls_init (tcbhead_t *tcb)
 {
   error_t err;
   thread_t self = __mach_thread_self ();
+  extern mach_port_t __hurd_reply_port0;
 
   /* We always at least start the sigthread anyway.  */
   tcb->multiple_threads = 1;
+  /* Take over the reply port we've been using.  */
+  tcb->reply_port = __hurd_reply_port0;
 
   err = _hurd_tls_new (self, tcb);
   if (err == 0)
-    __libc_tls_initialized = 1;
+    {
+      __libc_tls_initialized = 1;
+      /* This port is now owned by the TCB.  */
+      __hurd_reply_port0 = MACH_PORT_NULL;
+    }
   __mach_port_deallocate (__mach_task_self (), self);
   return err == 0;
 }