From 66d2029d65e4a5e0fb6366c6acf8ca10768e6b8f Mon Sep 17 00:00:00 2001 From: rcombs Date: Tue, 5 May 2020 21:31:52 -0500 Subject: render: handle more allocation failures in ass_renderer_init --- libass/ass_render.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'libass') diff --git a/libass/ass_render.c b/libass/ass_render.c index 01f7a5a..cf84122 100644 --- a/libass/ass_render.c +++ b/libass/ass_render.c @@ -52,7 +52,7 @@ ASS_Renderer *ass_renderer_init(ASS_Library *library) error = FT_Init_FreeType(&ft); if (error) { ass_msg(library, MSGL_FATAL, "%s failed", "FT_Init_FreeType"); - goto ass_init_exit; + goto fail; } FT_Library_Version(ft, &vmajor, &vminor, &vpatch); @@ -62,7 +62,7 @@ ASS_Renderer *ass_renderer_init(ASS_Library *library) priv = calloc(1, sizeof(ASS_Renderer)); if (!priv) { FT_Done_FreeType(ft); - goto ass_init_exit; + goto fail; } priv->library = library; @@ -81,15 +81,16 @@ ASS_Renderer *ass_renderer_init(ASS_Library *library) #endif if (!rasterizer_init(&priv->rasterizer, priv->engine->tile_order, - RASTERIZER_PRECISION)) { - FT_Done_FreeType(ft); - goto ass_init_exit; - } + RASTERIZER_PRECISION)) + goto fail; priv->cache.font_cache = ass_font_cache_create(); priv->cache.bitmap_cache = ass_bitmap_cache_create(); priv->cache.composite_cache = ass_composite_cache_create(); priv->cache.outline_cache = ass_outline_cache_create(); + if (!priv->cache.font_cache || !priv->cache.bitmap_cache || !priv->cache.composite_cache || !priv->cache.outline_cache) + goto fail; + priv->cache.glyph_max = GLYPH_CACHE_MAX; priv->cache.bitmap_max_size = BITMAP_CACHE_MAX_SIZE; priv->cache.composite_max_size = COMPOSITE_CACHE_MAX_SIZE; @@ -101,11 +102,15 @@ ASS_Renderer *ass_renderer_init(ASS_Library *library) priv->text_info.combined_bitmaps = calloc(MAX_BITMAPS_INITIAL, sizeof(CombinedBitmapInfo)); priv->text_info.glyphs = calloc(MAX_GLYPHS_INITIAL, sizeof(GlyphInfo)); priv->text_info.lines = calloc(MAX_LINES_INITIAL, sizeof(LineInfo)); + if (!priv->text_info.combined_bitmaps || !priv->text_info.glyphs || !priv->text_info.lines) + goto fail; priv->settings.font_size_coeff = 1.; priv->settings.selective_style_overrides = ASS_OVERRIDE_BIT_SELECTIVE_FONT_SCALE; - priv->shaper = ass_shaper_new(0); + if (!(priv->shaper = ass_shaper_new(0))) + goto fail; + ass_shaper_info(library); #ifdef CONFIG_HARFBUZZ priv->settings.shaper = ASS_SHAPING_COMPLEX; @@ -113,13 +118,15 @@ ASS_Renderer *ass_renderer_init(ASS_Library *library) priv->settings.shaper = ASS_SHAPING_SIMPLE; #endif - ass_init_exit: - if (priv) - ass_msg(library, MSGL_V, "Initialized"); - else - ass_msg(library, MSGL_ERR, "Initialization failed"); + ass_msg(library, MSGL_V, "Initialized"); return priv; + +fail: + ass_msg(library, MSGL_ERR, "Initialization failed"); + ass_renderer_done(priv); + + return NULL; } void ass_renderer_done(ASS_Renderer *render_priv) -- cgit v1.2.3