diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-09-15 20:03:03 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-09-16 17:28:29 +0100 |
commit | eeffd8b996051cc765dc389c8ca43d11692528fb (patch) | |
tree | 6bcb73b7be6d145d3f68d5311de3bea42b27f714 /platform/java | |
parent | 08dd88ba202cf67b43967d39032fa7a3604ad026 (diff) | |
download | mupdf-eeffd8b996051cc765dc389c8ca43d11692528fb.tar.xz |
Android JNI context fixes.
In the JNI code, we attach a cloned context onto each thread
we encounter in thread local storage. When the thread shuts
down, we should destroy that context.
This can theoretically be achieved on pthreads by using the
destructor registered to the tls slot. I have yet to see
Android ever actually call this destructor yet though.
No such mechanism exists for windows thread, so we'll just leak
here for now. There is a potential fix for this, but it's
hairy, so details are left in a comment in the code.
Diffstat (limited to 'platform/java')
-rw-r--r-- | platform/java/mupdf_native.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/platform/java/mupdf_native.c b/platform/java/mupdf_native.c index 823846bc..5723f4de 100644 --- a/platform/java/mupdf_native.c +++ b/platform/java/mupdf_native.c @@ -618,16 +618,30 @@ static void fin_base_context(JNIEnv *env) base_context = NULL; } +#ifndef _WIN32 +static void drop_tls_context(void *arg) +{ + fz_context *ctx = (fz_context *)arg; + + fz_drop_context(ctx); +} +#endif + static int init_base_context(JNIEnv *env) { int i; #ifdef _WIN32 + /* No destructor on windows. We will leak contexts. + * There is no easy way around this, but this page: + * http://stackoverflow.com/questions/3241732/is-there-anyway-to-dynamically-free-thread-local-storage-in-the-win32-apis/3245082#3245082 + * suggests a workaround that we can implement if we + * need to. */ context_key = TlsAlloc(); if (context_key == TLS_OUT_OF_INDEXES) return -1; #else - pthread_key_create(&context_key, NULL); + pthread_key_create(&context_key, drop_tls_context); #endif for (i = 0; i < FZ_LOCK_MAX; i++) |