From 8c0b958c8cd04eae8a65803db700240123fd38be Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 6 Jan 2012 11:56:46 +0000 Subject: Various memory leak fixes. In error cases, ensure we free objects correctly. Thanks to Zeniko for finding the problems (and many of the solutions!) --- fitz/filt_jbig2d.c | 2 ++ fitz/res_font.c | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'fitz') diff --git a/fitz/filt_jbig2d.c b/fitz/filt_jbig2d.c index 2d2e2eb9..3afcbcb0 100644 --- a/fitz/filt_jbig2d.c +++ b/fitz/filt_jbig2d.c @@ -112,10 +112,12 @@ fz_open_jbig2d(fz_stream *chain, fz_buffer *globals) if (state->ctx) jbig2_ctx_free(state->ctx); } + fz_drop_buffer(ctx, globals); fz_free(ctx, state); fz_close(chain); fz_rethrow(ctx); } + fz_drop_buffer(ctx, globals); return fz_new_stream(ctx, state, read_jbig2d, close_jbig2d); } diff --git a/fitz/res_font.c b/fitz/res_font.c index 38d6fdf1..053b2a04 100644 --- a/fitz/res_font.c +++ b/fitz/res_font.c @@ -209,7 +209,10 @@ fz_new_font_from_file(fz_context *ctx, char *path, int index) fterr = FT_New_Face(ctx->font->ftlib, path, index, &face); if (fterr) + { + fz_finalize_freetype(ctx); fz_throw(ctx, "freetype: cannot load font: %s", ft_error_string(fterr)); + } font = fz_new_font(ctx, face->family_name); font->ft_face = face; @@ -232,7 +235,10 @@ fz_new_font_from_memory(fz_context *ctx, unsigned char *data, int len, int index fterr = FT_New_Memory_Face(ctx->font->ftlib, data, len, index, &face); if (fterr) + { + fz_finalize_freetype(ctx); fz_throw(ctx, "freetype: cannot load font: %s", ft_error_string(fterr)); + } font = fz_new_font(ctx, face->family_name); font->ft_face = face; -- cgit v1.2.3