xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 1 of 3] libxc: free thread specific hypercall buffer on xc_interface_close
Date: Mon, 02 Aug 2010 13:31:11 +0100	[thread overview]
Message-ID: <b3e1074b137c03131cea.1280752271@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1280752270@localhost.localdomain>

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1280752237 -3600
# Node ID b3e1074b137c03131cea33c5100cbc2fa6cc5d5f
# Parent  f5f5949d98f0104ad1422ddacded20875f23d38d
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>

diff -r f5f5949d98f0 -r b3e1074b137c tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c	Fri Jul 30 09:13:11 2010 +0100
+++ b/tools/libxc/xc_private.c	Mon Aug 02 13:30:37 2010 +0100
@@ -57,6 +57,8 @@ xc_interface *xc_interface_open(xentooll
     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 @@ int hcall_buf_prep(void **addr, size_t l
 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)
@@ -223,6 +230,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)

  reply	other threads:[~2010-08-02 12:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-02 12:31 [PATCH 0 of 3] libxl: memory leaks Ian Campbell
2010-08-02 12:31 ` Ian Campbell [this message]
2010-08-02 12:31 ` [PATCH 2 of 3] libxl: fix memory leak in libxl_name_to_domid Ian Campbell
2010-08-02 12:31 ` [PATCH 3 of 3] xl: fix memory leaks in xl create Ian Campbell
2010-08-02 13:11 ` [PATCH 0 of 3] libxl: memory leaks Gianni Tedesco
2010-08-02 13:20   ` Vincent Hanquez
2010-08-02 14:05     ` Gianni Tedesco
2010-08-03  7:59       ` Vincent Hanquez
2010-08-03 10:18         ` Gianni Tedesco
2010-08-03 10:51           ` Vincent Hanquez
2010-08-03 12:16             ` Gianni Tedesco
2010-08-03 13:37               ` Vincent Hanquez
2010-08-03 14:02                 ` Gianni Tedesco
2010-08-03 14:51                 ` Ian Campbell
2010-08-03 17:07                   ` Stefano Stabellini
2010-08-03 17:11 ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3e1074b137c03131cea.1280752271@localhost.localdomain \
    --to=ian.campbell@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).