summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2011-12-15 19:49:16 +0000
committerRobin Watts <robin.watts@artifex.com>2011-12-15 19:49:16 +0000
commite6118ac1b13cc49f637861fccbc32a10c4ea1ea7 (patch)
tree4ccb1fb5adf96d7794872502ee975825f250054a /fitz
parent3031a2480fe775df825de6674495d01ae2607d93 (diff)
downloadmupdf-e6118ac1b13cc49f637861fccbc32a10c4ea1ea7.tar.xz
Various Memsqueezing fixes.
Fixes for leaks (and SEGVs, division by zeros etc) seen when Memsqueezing.
Diffstat (limited to 'fitz')
-rw-r--r--fitz/base_hash.c12
-rw-r--r--fitz/base_object.c20
-rw-r--r--fitz/memento.c2
-rw-r--r--fitz/res_store.c10
-rw-r--r--fitz/stm_open.c10
5 files changed, 47 insertions, 7 deletions
diff --git a/fitz/base_hash.c b/fitz/base_hash.c
index d6ff8ca0..79943a1d 100644
--- a/fitz/base_hash.c
+++ b/fitz/base_hash.c
@@ -54,8 +54,16 @@ fz_new_hash_table(fz_context *ctx, int initialsize, int keylen)
table->keylen = keylen;
table->size = initialsize;
table->load = 0;
- table->ents = fz_malloc_array(ctx, table->size, sizeof(fz_hash_entry));
- memset(table->ents, 0, sizeof(fz_hash_entry) * table->size);
+ fz_try(ctx)
+ {
+ table->ents = fz_malloc_array(ctx, table->size, sizeof(fz_hash_entry));
+ memset(table->ents, 0, sizeof(fz_hash_entry) * table->size);
+ }
+ fz_catch(ctx)
+ {
+ fz_free(ctx, table);
+ fz_rethrow(ctx);
+ }
return table;
}
diff --git a/fitz/base_object.c b/fitz/base_object.c
index 957396ea..ced40414 100644
--- a/fitz/base_object.c
+++ b/fitz/base_object.c
@@ -389,7 +389,15 @@ fz_new_array(fz_context *ctx, int initialcap)
obj->u.a.len = 0;
obj->u.a.cap = initialcap > 1 ? initialcap : 6;
- obj->u.a.items = fz_malloc_array(ctx, obj->u.a.cap, sizeof(fz_obj*));
+ fz_try(ctx)
+ {
+ obj->u.a.items = fz_malloc_array(ctx, obj->u.a.cap, sizeof(fz_obj*));
+ }
+ fz_catch(ctx)
+ {
+ fz_free(ctx, obj);
+ fz_rethrow(ctx);
+ }
for (i = 0; i < obj->u.a.cap; i++)
obj->u.a.items[i] = NULL;
@@ -537,7 +545,15 @@ fz_new_dict(fz_context *ctx, int initialcap)
obj->u.d.len = 0;
obj->u.d.cap = initialcap > 1 ? initialcap : 10;
- obj->u.d.items = fz_malloc_array(ctx, obj->u.d.cap, sizeof(struct keyval));
+ fz_try(ctx)
+ {
+ obj->u.d.items = fz_malloc_array(ctx, obj->u.d.cap, sizeof(struct keyval));
+ }
+ fz_catch(ctx)
+ {
+ fz_free(ctx, obj);
+ fz_rethrow(ctx);
+ }
for (i = 0; i < obj->u.d.cap; i++)
{
obj->u.d.items[i].k = NULL;
diff --git a/fitz/memento.c b/fitz/memento.c
index cb5b59d1..73963f2d 100644
--- a/fitz/memento.c
+++ b/fitz/memento.c
@@ -446,7 +446,7 @@ static void Memento_endStats(void)
fprintf(stderr, "%d mallocs, %d frees, %d reallocs\n", globals.numMallocs,
globals.numFrees, globals.numReallocs);
fprintf(stderr, "Average allocation size %d bytes\n",
- globals.totalAlloc/globals.numMallocs);
+ (globals.numMallocs != 0 ? globals.totalAlloc/globals.numMallocs: 0));
}
void Memento_stats(void)
diff --git a/fitz/res_store.c b/fitz/res_store.c
index 0b303982..a76a9bb1 100644
--- a/fitz/res_store.c
+++ b/fitz/res_store.c
@@ -39,7 +39,15 @@ fz_new_store_context(fz_context *ctx, unsigned int max)
{
fz_store *store;
store = fz_malloc(ctx, sizeof(fz_store));
- store->hash = fz_new_hash_table(ctx, 4096, sizeof(struct refkey));
+ fz_try(ctx)
+ {
+ store->hash = fz_new_hash_table(ctx, 4096, sizeof(struct refkey));
+ }
+ fz_catch(ctx)
+ {
+ fz_free(ctx, store);
+ fz_rethrow(ctx);
+ }
store->head = NULL;
store->tail = NULL;
store->size = 0;
diff --git a/fitz/stm_open.c b/fitz/stm_open.c
index eade9788..733b4c6a 100644
--- a/fitz/stm_open.c
+++ b/fitz/stm_open.c
@@ -89,7 +89,15 @@ fz_open_fd(fz_context *ctx, int fd)
state = fz_malloc(ctx, sizeof(int));
*state = fd;
- stm = fz_new_stream(ctx, state, read_file, close_file);
+ fz_try(ctx)
+ {
+ stm = fz_new_stream(ctx, state, read_file, close_file);
+ }
+ fz_catch(ctx)
+ {
+ fz_free(ctx, state);
+ fz_rethrow(ctx);
+ }
stm->seek = seek_file;
return stm;