[Libguestfs] [PATCH nbdkit v2 2/3] server: connections: Don't free TLS storage of conn until end of function.

Richard W.M. Jones rjones at redhat.com
Tue Feb 11 17:39:42 UTC 2020


We want to do this as late as possible.  In particular, backend_close
may call plugin.close which may (although it's unlikely) call one of
the functions which relies on the implicit connection pointer fetched
through thread-local storage (TLS) which would then fail.
---
 server/connections.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/connections.c b/server/connections.c
index 66520fcb..9978afb4 100644
--- a/server/connections.c
+++ b/server/connections.c
@@ -331,7 +331,6 @@ free_connection (struct connection *conn)
   if (!conn)
     return;
 
-  threadlocal_set_conn (NULL);
   conn->close (conn);
   if (listen_stdin) {
     int fd;
@@ -368,6 +367,7 @@ free_connection (struct connection *conn)
 
   free (conn->handles);
   free (conn);
+  threadlocal_set_conn (NULL);
 }
 
 /* Write buffer to conn->sockout with send() and either succeed completely
-- 
2.25.0




More information about the Libguestfs mailing list