summaryrefslogtreecommitdiff
path: root/libusb/os
diff options
context:
space:
mode:
authorVitali Lovich <vlovich@gmail.com>2011-09-16 08:53:25 -0600
committerPeter Stuge <peter@stuge.se>2011-10-17 16:25:50 +0200
commitc471d55e909d84012f065715703dad454d1fa421 (patch)
treeb7fa614bd5ec90920bd828ca3dd82aed8c2b1ea4 /libusb/os
parent477f3917f8c123e36993f9c0ba8156ca0f16ccfa (diff)
downloadlibusb-c471d55e909d84012f065715703dad454d1fa421.tar.gz
Darwin: fix port leak in darwin_clock_gettime()
Diffstat (limited to 'libusb/os')
-rw-r--r--libusb/os/darwin_usb.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index 8de3f5f..d81e9f0 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -51,6 +51,9 @@
static pthread_mutex_t libusb_darwin_at_mutex;
static pthread_cond_t libusb_darwin_at_cond;
+static clock_serv_t clock_realtime;
+static clock_serv_t clock_monotonic;
+
static CFRunLoopRef libusb_darwin_acfl = NULL; /* async cf loop */
static int initCount = 0;
@@ -373,7 +376,16 @@ static void *event_thread_main (void *arg0) {
}
static int darwin_init(struct libusb_context *ctx) {
+ host_name_port_t host_self;
+
if (!(initCount++)) {
+ /* create the clocks that will be used */
+
+ host_self = mach_host_self();
+ host_get_clock_service(host_self, CALENDAR_CLOCK, &clock_realtime);
+ host_get_clock_service(host_self, SYSTEM_CLOCK, &clock_monotonic);
+ mach_port_deallocate(mach_task_self(), host_self);
+
pthread_mutex_init (&libusb_darwin_at_mutex, NULL);
pthread_cond_init (&libusb_darwin_at_cond, NULL);
@@ -390,6 +402,8 @@ static int darwin_init(struct libusb_context *ctx) {
static void darwin_exit (void) {
if (!(--initCount)) {
+ mach_port_deallocate(mach_task_self(), clock_realtime);
+ mach_port_deallocate(mach_task_self(), clock_monotonic);
/* stop the async runloop */
CFRunLoopStop (libusb_darwin_acfl);
@@ -1671,11 +1685,11 @@ static int darwin_clock_gettime(int clk_id, struct timespec *tp) {
switch (clk_id) {
case USBI_CLOCK_REALTIME:
/* CLOCK_REALTIME represents time since the epoch */
- host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &clock_ref);
+ clock_ref = clock_realtime;
break;
case USBI_CLOCK_MONOTONIC:
/* use system boot time as reference for the monotonic clock */
- host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &clock_ref);
+ clock_ref = clock_monotonic;
break;
default:
return LIBUSB_ERROR_INVALID_PARAM;