summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-04-29 11:52:09 +0100
committerRobin Watts <robin.watts@artifex.com>2013-04-29 13:00:14 +0100
commit7696a4678e1eee59488649ef20f7fbb4d7d3fc0c (patch)
tree095dc8589574d9a16d8d5e20be33045a6cc4310c /fitz
parentae40ceccb46df6d45e45c40b27f426286a46a7e6 (diff)
downloadmupdf-7696a4678e1eee59488649ef20f7fbb4d7d3fc0c.tar.xz
Add Memento build option to Android build. Fix memory leaks.
Following up on a report from a potential customer, fix various places in mupdf.c where we were leaking memory (devices not freed, context not properly freed etc). In order to track this down, I added a Memento build - just do: ndk-build MEMENTO=1 when building. This only checks for leaks, not for memory overwrites by default as it uses MEMENTO_LEAKONLY to avoid any possibility of the android kernel killing stuff for being too slow or using too much memory.
Diffstat (limited to 'fitz')
-rw-r--r--fitz/memento.c45
-rw-r--r--fitz/memento.h6
2 files changed, 39 insertions, 12 deletions
diff --git a/fitz/memento.c b/fitz/memento.c
index bbd0455f..9471b25f 100644
--- a/fitz/memento.c
+++ b/fitz/memento.c
@@ -19,12 +19,6 @@
* to speed the operation */
/* #define MEMENTO_LEAKONLY */
-#ifndef MEMENTO_STACKTRACE_METHOD
-#ifdef __GNUC__
-#define MEMENTO_STACKTRACE_METHOD 1
-#endif
-#endif
-
/* Don't keep blocks around if they'd mean losing more than a quarter of
* the freelist. */
#define MEMENTO_FREELIST_MAX_SINGLE_BLOCK (MEMENTO_FREELIST_MAX/4)
@@ -52,6 +46,29 @@ int atexit(void (*)(void));
#include <stdlib.h>
#endif
+#ifdef MEMENTO_ANDROID
+#include <android/log.h>
+
+static int
+android_fprintf(FILE *file, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ __android_log_vprint(ANDROID_LOG_ERROR,"memento", fmt, args);
+ va_end(args);
+}
+
+#define fprintf android_fprintf
+#define MEMENTO_STACKTRACE_METHOD 0
+#endif
+
+#ifndef MEMENTO_STACKTRACE_METHOD
+#ifdef __GNUC__
+#define MEMENTO_STACKTRACE_METHOD 1
+#endif
+#endif
+
#if defined(__linux__)
#define MEMENTO_HAS_FORK
#elif defined(__APPLE__) && defined(__MACH__)
@@ -476,8 +493,8 @@ static void blockDisplay(Memento_BlkHeader *b, int n)
n++;
while (n > 40)
{
- fprintf(stderr, "*");
- n -= 40;
+ fprintf(stderr, "*");
+ n -= 40;
}
while(n > 0)
{
@@ -507,14 +524,14 @@ static void doNestedDisplay(Memento_BlkHeader *b,
/* Try and avoid recursion if we can help it */
do {
blockDisplay(b, depth);
- if (b->sibling) {
+ if (b->sibling) {
if (b->child)
doNestedDisplay(b->child, depth+1);
b = b->sibling;
- } else {
+ } else {
b = b->child;
depth++;
- }
+ }
} while (b);
}
@@ -754,8 +771,12 @@ static void Memento_init(void)
/* stashed_map[j] = i means that filedescriptor i-1 was duplicated to j */
int stashed_map[OPEN_MAX];
+#ifdef MEMENTO_STACKTRACE_METHOD
+#if MEMENTO_STACKTRACE_METHOD == 1
extern size_t backtrace(void **, int);
extern void backtrace_symbols_fd(void **, size_t, int);
+#endif
+#endif
static void Memento_signal(void)
{
@@ -851,7 +872,7 @@ static void Memento_signal(void)
globals.segv = 1;
/* If we just return from this function the SEGV will be unhandled, and
* we'll launch into whatever JIT debugging system the OS provides. At
- * least output something useful first. If MEMENTO_NOJIT is set, then
+ * least fprintf(stderr, something useful first. If MEMENTO_NOJIT is set, then
* just exit to avoid the JIT (and get the usual atexit handling). */
if (getenv("MEMENTO_NOJIT"))
exit(1);
diff --git a/fitz/memento.h b/fitz/memento.h
index 4831349b..75354384 100644
--- a/fitz/memento.h
+++ b/fitz/memento.h
@@ -137,6 +137,12 @@
#include <memory.h>
+#ifdef __ANDROID__
+#define MEMENTO_ANDROID
+#include <stdio.h>
+#include <stdlib.h>
+#endif
+
#define MEMENTO_H
#ifndef MEMENTO_UNDERLYING_MALLOC