summaryrefslogtreecommitdiff
path: root/source/fitz/util.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-12-14 16:46:53 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-12-16 02:16:58 +0100
commit7a737ecb89f3da42119487ac85aab3ba59bb335a (patch)
tree70a1b2d63146a1078562acc74f968cfcaa8e8131 /source/fitz/util.c
parentcb96a2d638b2b227b54c3b963b30ec26f2265ab5 (diff)
downloadmupdf-7a737ecb89f3da42119487ac85aab3ba59bb335a.tar.xz
Fix memory leaks on errors in text searching utility functions.
Diffstat (limited to 'source/fitz/util.c')
-rw-r--r--source/fitz/util.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/source/fitz/util.c b/source/fitz/util.c
index cc2c9c7e..8d32346e 100644
--- a/source/fitz/util.c
+++ b/source/fitz/util.c
@@ -343,42 +343,52 @@ fz_new_stext_page_from_page_number(fz_context *ctx, fz_document *doc, int number
int
fz_search_display_list(fz_context *ctx, fz_display_list *list, const char *needle, fz_rect *hit_bbox, int hit_max)
{
- fz_stext_sheet *sheet;
- fz_stext_page *text;
+ fz_stext_sheet *sheet = NULL;
+ fz_stext_page *text = NULL;
int count;
- sheet = fz_new_stext_sheet(ctx);
+ fz_var(sheet);
+ fz_var(text);
+
fz_try(ctx)
{
+ sheet = fz_new_stext_sheet(ctx);
text = fz_new_stext_page_from_display_list(ctx, list, sheet, NULL);
count = fz_search_stext_page(ctx, text, needle, hit_bbox, hit_max);
}
fz_always(ctx)
+ {
+ fz_drop_stext_page(ctx, text);
fz_drop_stext_sheet(ctx, sheet);
+ }
fz_catch(ctx)
fz_rethrow(ctx);
- fz_drop_stext_page(ctx, text);
return count;
}
int
fz_search_page(fz_context *ctx, fz_page *page, const char *needle, fz_rect *hit_bbox, int hit_max)
{
- fz_stext_sheet *sheet;
- fz_stext_page *text;
+ fz_stext_sheet *sheet = NULL;
+ fz_stext_page *text = NULL;
int count;
- sheet = fz_new_stext_sheet(ctx);
+ fz_var(sheet);
+ fz_var(text);
+
fz_try(ctx)
{
+ sheet = fz_new_stext_sheet(ctx);
text = fz_new_stext_page_from_page(ctx, page, sheet, NULL);
count = fz_search_stext_page(ctx, text, needle, hit_bbox, hit_max);
}
fz_always(ctx)
+ {
+ fz_drop_stext_page(ctx, text);
fz_drop_stext_sheet(ctx, sheet);
+ }
fz_catch(ctx)
fz_rethrow(ctx);
- fz_drop_stext_page(ctx, text);
return count;
}