Mercurial > mplayer.hg
changeset 31875:ac6e48baa03d
Import libass 0.9.11
This version fixes a (sometimes pretty bad) memory leak.
author | greg |
---|---|
date | Wed, 11 Aug 2010 01:14:37 +0000 |
parents | cedbffa1629d |
children | c52e80f24086 |
files | libass/ass.c libass/ass.h libass/ass_bitmap.c libass/ass_drawing.c libass/ass_drawing.h libass/ass_font.c libass/ass_fontconfig.c libass/ass_library.c libass/ass_parse.c libass/ass_render.c libass/ass_utils.c |
diffstat | 11 files changed, 60 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/libass/ass.c Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass.c Wed Aug 11 01:14:37 2010 +0000 @@ -23,6 +23,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <strings.h> #include <assert.h> #include <errno.h> #include <sys/types.h> @@ -64,26 +65,22 @@ int i; if (track->parser_priv) { - if (track->parser_priv->fontname) - free(track->parser_priv->fontname); - if (track->parser_priv->fontdata) - free(track->parser_priv->fontdata); + free(track->parser_priv->fontname); + free(track->parser_priv->fontdata); free(track->parser_priv); } - if (track->style_format) - free(track->style_format); - if (track->event_format) - free(track->event_format); + free(track->style_format); + free(track->event_format); if (track->styles) { for (i = 0; i < track->n_styles; ++i) ass_free_style(track, i); - free(track->styles); } + free(track->styles); if (track->events) { for (i = 0; i < track->n_events; ++i) ass_free_event(track, i); - free(track->events); } + free(track->events); free(track->name); free(track); } @@ -135,23 +132,19 @@ void ass_free_event(ASS_Track *track, int eid) { ASS_Event *event = track->events + eid; - if (event->Name) - free(event->Name); - if (event->Effect) - free(event->Effect); - if (event->Text) - free(event->Text); - if (event->render_priv) - free(event->render_priv); + + free(event->Name); + free(event->Effect); + free(event->Text); + free(event->render_priv); } void ass_free_style(ASS_Track *track, int sid) { ASS_Style *style = track->styles + sid; - if (style->Name) - free(style->Name); - if (style->FontName) - free(style->FontName); + + free(style->Name); + free(style->FontName); } // ============================================================================================== @@ -593,6 +586,7 @@ if (!strncmp(str, "Format:", 7)) { char *p = str + 7; skip_spaces(&p); + free(track->event_format); track->event_format = strdup(p); ass_msg(track->library, MSGL_DBG2, "Event format: %s", track->event_format); } else if (!strncmp(str, "Dialogue:", 9)) { @@ -673,12 +667,10 @@ if (track->library->extract_fonts) { ass_add_font(track->library, track->parser_priv->fontname, (char *) buf, dsize); - buf = 0; } - error_decode_font: - if (buf) - free(buf); +error_decode_font: + free(buf); free(track->parser_priv->fontname); free(track->parser_priv->fontdata); track->parser_priv->fontname = 0;
--- a/libass/ass.h Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass.h Wed Aug 11 01:14:37 2010 +0000 @@ -25,7 +25,7 @@ #include <stdarg.h> #include "ass_types.h" -#define LIBASS_VERSION 0x00910000 +#define LIBASS_VERSION 0x00911000 /* * A linked list of images produced by an ass renderer.
--- a/libass/ass_bitmap.c Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass_bitmap.c Wed Aug 11 01:14:37 2010 +0000 @@ -113,8 +113,7 @@ priv->tmp_w *= 2; while (priv->tmp_h < h) priv->tmp_h *= 2; - if (priv->tmp) - free(priv->tmp); + free(priv->tmp); priv->tmp = malloc((priv->tmp_w + 1) * priv->tmp_h * sizeof(short)); } @@ -127,12 +126,9 @@ void ass_synth_done(ASS_SynthPriv *priv) { - if (priv->tmp) - free(priv->tmp); - if (priv->g) - free(priv->g); - if (priv->gt2) - free(priv->gt2); + free(priv->tmp); + free(priv->g); + free(priv->gt2); free(priv); } @@ -149,11 +145,9 @@ void ass_free_bitmap(Bitmap *bm) { - if (bm) { - if (bm->buffer) - free(bm->buffer); - free(bm); - } + if (bm) + free(bm->buffer); + free(bm); } static Bitmap *copy_bitmap(const Bitmap *src)
--- a/libass/ass_drawing.c Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass_drawing.c Wed Aug 11 01:14:37 2010 +0000 @@ -34,13 +34,13 @@ * \brief Get and prepare a FreeType glyph */ static void drawing_make_glyph(ASS_Drawing *drawing, void *fontconfig_priv, - ASS_Font *font, ASS_Hinting hint) + ASS_Font *font) { FT_OutlineGlyph glyph; // This is hacky... glyph = (FT_OutlineGlyph) ass_font_get_glyph(fontconfig_priv, font, - (uint32_t) ' ', hint, 0); + (uint32_t) ' ', 0, 0); if (glyph) { FT_Outline_Done(drawing->ftlibrary, &glyph->outline); FT_Outline_New(drawing->ftlibrary, GLYPH_INITIAL_POINTS, @@ -355,7 +355,7 @@ * \brief Create and initialize a new drawing and return it */ ASS_Drawing *ass_drawing_new(void *fontconfig_priv, ASS_Font *font, - ASS_Hinting hint, FT_Library lib) + FT_Library lib) { ASS_Drawing *drawing; @@ -364,12 +364,10 @@ drawing->size = DRAWING_INITIAL_SIZE; drawing->cbox.xMin = drawing->cbox.yMin = INT_MAX; drawing->cbox.xMax = drawing->cbox.yMax = INT_MIN; - + drawing->fontconfig_priv = fontconfig_priv; + drawing->font = font; drawing->ftlibrary = lib; - if (font) { - drawing->library = font->library; - drawing_make_glyph(drawing, fontconfig_priv, font, hint); - } + drawing->library = font->library; drawing->scale_x = 1.; drawing->scale_y = 1.; @@ -422,6 +420,8 @@ ASS_DrawingToken *token; FT_Vector pen = {0, 0}; + if (drawing->font) + drawing_make_glyph(drawing, drawing->fontconfig_priv, drawing->font); if (!drawing->glyph) return NULL;
--- a/libass/ass_drawing.h Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass_drawing.h Wed Aug 11 01:14:37 2010 +0000 @@ -57,7 +57,9 @@ int hash; // hash value (for caching) // private - FT_Library ftlibrary; // FT library instance, needed for font ops + FT_Library ftlibrary; // needed for font ops + ASS_Font *font; // dito + void *fontconfig_priv; // dito ASS_Library *library; int size; // current buffer size ASS_DrawingToken *tokens; // tokenized drawing @@ -69,7 +71,7 @@ } ASS_Drawing; ASS_Drawing *ass_drawing_new(void *fontconfig_priv, ASS_Font *font, - ASS_Hinting hint, FT_Library lib); + FT_Library lib); void ass_drawing_free(ASS_Drawing* drawing); void ass_drawing_add_char(ASS_Drawing* drawing, char symbol); void ass_drawing_hash(ASS_Drawing* drawing);
--- a/libass/ass_font.c Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass_font.c Wed Aug 11 01:14:37 2010 +0000 @@ -27,6 +27,7 @@ #include FT_GLYPH_H #include FT_TRUETYPE_TABLES_H #include FT_OUTLINE_H +#include <strings.h> #include "ass.h" #include "ass_library.h" @@ -561,8 +562,7 @@ for (i = 0; i < font->n_faces; ++i) if (font->faces[i]) FT_Done_Face(font->faces[i]); - if (font->desc.family) - free(font->desc.family); + free(font->desc.family); free(font); }
--- a/libass/ass_fontconfig.c Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass_fontconfig.c Wed Aug 11 01:14:37 2010 +0000 @@ -24,6 +24,7 @@ #include <stdio.h> #include <assert.h> #include <string.h> +#include <strings.h> #include <sys/types.h> #include <sys/stat.h> #include <inttypes.h> @@ -520,14 +521,13 @@ void fontconfig_done(FCInstance *priv) { + + if (priv) { #ifdef CONFIG_FONTCONFIG - if (priv && priv->config) FcConfigDestroy(priv->config); #endif - if (priv && priv->path_default) free(priv->path_default); - if (priv && priv->family_default) free(priv->family_default); - if (priv) - free(priv); + } + free(priv); }
--- a/libass/ass_library.c Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass_library.c Wed Aug 11 01:14:37 2010 +0000 @@ -18,6 +18,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "config.h" + #include <inttypes.h> #include <stdio.h> #include <stdlib.h> @@ -57,8 +59,7 @@ void ass_set_fonts_dir(ASS_Library *priv, const char *fonts_dir) { - if (priv->fonts_dir) - free(priv->fonts_dir); + free(priv->fonts_dir); priv->fonts_dir = fonts_dir ? strdup(fonts_dir) : 0; } @@ -77,8 +78,8 @@ if (priv->style_overrides) { for (p = priv->style_overrides; *p; ++p) free(*p); - free(priv->style_overrides); } + free(priv->style_overrides); if (!list) return;
--- a/libass/ass_parse.c Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass_parse.c Wed Aug 11 01:14:37 2010 +0000 @@ -214,13 +214,14 @@ { int scale = 1; int res = 0; - ASS_Drawing *drawing; + ASS_Drawing *drawing = render_priv->state.clip_drawing; - ass_drawing_free(render_priv->state.clip_drawing); + if (drawing && drawing->glyph) + FT_Done_Glyph((FT_Glyph) drawing->glyph); + ass_drawing_free(drawing); render_priv->state.clip_drawing = ass_drawing_new( render_priv->fontconfig_priv, render_priv->state.font, - render_priv->settings.hinting, render_priv->ftlibrary); drawing = render_priv->state.clip_drawing; skipopt('('); @@ -454,8 +455,7 @@ family[p - start] = '\0'; } else family = strdup(render_priv->state.style->FontName); - if (render_priv->state.family) - free(render_priv->state.family); + free(render_priv->state.family); render_priv->state.family = family; update_font(render_priv); } else if (mystrcmp(&p, "alpha")) {
--- a/libass/ass_render.c Tue Aug 10 13:33:49 2010 +0000 +++ b/libass/ass_render.c Wed Aug 11 01:14:37 2010 +0000 @@ -145,14 +145,13 @@ FT_Stroker_Done(render_priv->state.stroker); render_priv->state.stroker = 0; } - if (render_priv && render_priv->ftlibrary) + if (render_priv->ftlibrary) FT_Done_FreeType(render_priv->ftlibrary); - if (render_priv && render_priv->fontconfig_priv) + if (render_priv->fontconfig_priv) fontconfig_done(render_priv->fontconfig_priv); - if (render_priv && render_priv->synth_priv) + if (render_priv->synth_priv) ass_synth_done(render_priv->synth_priv); - if (render_priv && render_priv->eimg) - free(render_priv->eimg); + free(render_priv->eimg); free(render_priv->text_info.glyphs); free(render_priv->text_info.lines); @@ -911,9 +910,9 @@ render_priv->state.effect_type = EF_NONE; render_priv->state.effect_timing = 0; render_priv->state.effect_skip_timing = 0; + ass_drawing_free(render_priv->state.drawing); render_priv->state.drawing = ass_drawing_new(render_priv->fontconfig_priv, render_priv->state.font, - render_priv->settings.hinting, render_priv->ftlibrary); apply_transition_effects(render_priv, event); @@ -1900,7 +1899,6 @@ drawing = render_priv->state.drawing = ass_drawing_new(render_priv->fontconfig_priv, render_priv->state.font, - render_priv->settings.hinting, render_priv->ftlibrary); } }