aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xc_private.c
diff options
context:
space:
mode:
authorIan Campbell <ian.campbell@citrix.com>2010-07-30 16:20:48 +0100
committerIan Campbell <ian.campbell@citrix.com>2010-07-30 16:20:48 +0100
commita543f084db7a5d25c511f4121d27a8e27c215e38 (patch)
tree9e610adf2dd9e2a9cee54d9c4ec84a84892adef2 /tools/libxc/xc_private.c
parentafc6c57b6d604614433d214eca24ad16bc770d08 (diff)
downloadxen-a543f084db7a5d25c511f4121d27a8e27c215e38.tar.gz
xen-a543f084db7a5d25c511f4121d27a8e27c215e38.tar.bz2
xen-a543f084db7a5d25c511f4121d27a8e27c215e38.zip
libxc: free thread specific hypercall buffer on xc_interface_close
The per-thread hypercall buffer is usually cleaned up on pthread_exit by the destructor passed to pthread_key_create. However if the calling application is not threaded then the destructor is never called. This frees the data for the current thread only but that is OK since any other threads will be cleaned up by the destructor. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxc/xc_private.c')
-rw-r--r--tools/libxc/xc_private.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
index befc3f965a..f1d224d2fb 100644
--- a/tools/libxc/xc_private.c
+++ b/tools/libxc/xc_private.c
@@ -57,6 +57,8 @@ xc_interface *xc_interface_open(xentoollog_logger *logger,
return 0;
}
+static void xc_clean_hcall_buf(void);
+
int xc_interface_close(xc_interface *xch)
{
int rc = 0;
@@ -68,6 +70,9 @@ int xc_interface_close(xc_interface *xch)
rc = xc_interface_close_core(xch, xch->fd);
if (rc) PERROR("Could not close hypervisor interface");
}
+
+ xc_clean_hcall_buf();
+
free(xch);
return rc;
}
@@ -180,6 +185,8 @@ void unlock_pages(void *addr, size_t len) { }
int hcall_buf_prep(void **addr, size_t len) { return 0; }
void hcall_buf_release(void **addr, size_t len) { }
+static void xc_clean_hcall_buf(void) { }
+
#else /* !__sun__ */
int lock_pages(void *addr, size_t len)
@@ -225,6 +232,14 @@ static void _xc_clean_hcall_buf(void *m)
pthread_setspecific(hcall_buf_pkey, NULL);
}
+static void xc_clean_hcall_buf(void)
+{
+ void *hcall_buf = pthread_getspecific(hcall_buf_pkey);
+
+ if (hcall_buf)
+ _xc_clean_hcall_buf(hcall_buf);
+}
+
static void _xc_init_hcall_buf(void)
{
pthread_key_create(&hcall_buf_pkey, _xc_clean_hcall_buf);