diff options
author | zeniko <zeniko@gmail.com> | 2013-06-01 21:33:12 +0200 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-06-03 16:22:04 +0100 |
commit | 24dc461099b9e50fea6d724a27979bb6e331d4aa (patch) | |
tree | 0ebae11177a17b727dd9126dc40c7bf55d123f5e | |
parent | a727aacc2d4feb0c6f5c609e05a0d5611aa97292 (diff) | |
download | mupdf-24dc461099b9e50fea6d724a27979bb6e331d4aa.tar.xz |
prevent memory leak and unexpected exception
fz_free_device usually doesn't throw (throwing in clean-up code is
quite pointless anyway) but freeing the text extraction device might
do so under memory pressure. This patch catches any potential
exception to guarantee a proper clean-up.
-rw-r--r-- | fitz/text_extract.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/fitz/text_extract.c b/fitz/text_extract.c index 3bb0db56..45e0395a 100644 --- a/fitz/text_extract.c +++ b/fitz/text_extract.c @@ -951,18 +951,29 @@ fz_text_free_user(fz_device *dev) fz_context *ctx = dev->ctx; fz_text_device *tdev = dev->user; - add_span_to_soup(tdev->spans, tdev->cur_span); - tdev->cur_span = NULL; + fz_try(ctx) + { - strain_soup(ctx, tdev); - free_span_soup(tdev->spans); + add_span_to_soup(tdev->spans, tdev->cur_span); + tdev->cur_span = NULL; - /* TODO: smart sorting of blocks in reading order */ - /* TODO: unicode NFC normalization */ + strain_soup(ctx, tdev); - fz_bidi_reorder_text_page(ctx, tdev->page); + /* TODO: smart sorting of blocks in reading order */ + /* TODO: unicode NFC normalization */ - fz_free(dev->ctx, tdev); + fz_bidi_reorder_text_page(ctx, tdev->page); + } + fz_always(ctx) + { + free_span_soup(tdev->spans); + fz_free(dev->ctx, tdev); + } + fz_catch(ctx) + { + /* TODO: mark fz_free_device as "doesn't throw" (else rethrowing would + have to be caught/rethrown again in fz_free_device) */ + } } fz_device * |