diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2013-06-25 13:43:31 +0100 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2013-06-25 13:44:17 +0100 |
commit | 64140fa7f404f7499a72a255118c7243363b93dd (patch) | |
tree | 08335bf48e8546ef814d28e96367ee8f440ba987 /source/pdf | |
parent | 19a0eff677d6e046fe4af169b1bed32414a7dfe3 (diff) | |
download | mupdf-64140fa7f404f7499a72a255118c7243363b93dd.tar.xz |
Fix potential memory leak
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-annot.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index a46f67b7..453e9bfb 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -484,6 +484,7 @@ pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) fz_var(annot); fz_var(itr); + fz_var(head); head = tail = NULL; @@ -494,22 +495,30 @@ pdf_load_annots(pdf_document *doc, pdf_obj *annots, pdf_page *page) the annot array, so we don't want to be iterating through the array while that happens. */ - for (i = 0; i < len; i++) + fz_try(ctx) { - obj = pdf_array_get(annots, i); - annot = fz_malloc_struct(ctx, pdf_annot); - annot->obj = pdf_keep_obj(obj); - annot->page = page; - annot->next = NULL; - - if (!head) - head = tail = annot; - else + for (i = 0; i < len; i++) { - tail->next = annot; - tail = annot; + obj = pdf_array_get(annots, i); + annot = fz_malloc_struct(ctx, pdf_annot); + annot->obj = pdf_keep_obj(obj); + annot->page = page; + annot->next = NULL; + + if (!head) + head = tail = annot; + else + { + tail->next = annot; + tail = annot; + } } } + fz_catch(ctx) + { + pdf_free_annot(ctx, head); + fz_rethrow(ctx); + } /* Iterate through the newly created annot linked list, using a double pointer to |