[MPlayer-cvslog] r31956 - in trunk/libass: ass.c ass.h ass_bitmap.c ass_drawing.c ass_drawing.h ass_font.c ass_fontconfig.c ass_library.c ass_parse.c ass_render.c ass_utils.c

greg subversion at mplayerhq.hu
Wed Aug 11 03:14:38 CEST 2010


Author: greg
Date: Wed Aug 11 03:14:37 2010
New Revision: 31956

Log:
Import libass 0.9.11

This version fixes a (sometimes pretty bad) memory leak.

Modified:
   trunk/libass/ass.c
   trunk/libass/ass.h
   trunk/libass/ass_bitmap.c
   trunk/libass/ass_drawing.c
   trunk/libass/ass_drawing.h
   trunk/libass/ass_font.c
   trunk/libass/ass_fontconfig.c
   trunk/libass/ass_library.c
   trunk/libass/ass_parse.c
   trunk/libass/ass_render.c
   trunk/libass/ass_utils.c

Modified: trunk/libass/ass.c
==============================================================================
--- trunk/libass/ass.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -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 @@ void ass_free_track(ASS_Track *track)
     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 @@ int ass_alloc_event(ASS_Track *track)
 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 @@ static int process_events_line(ASS_Track
     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 @@ static int decode_font(ASS_Track *track)
     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;

Modified: trunk/libass/ass.h
==============================================================================
--- trunk/libass/ass.h	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass.h	Wed Aug 11 03:14:37 2010	(r31956)
@@ -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.

Modified: trunk/libass/ass_bitmap.c
==============================================================================
--- trunk/libass/ass_bitmap.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_bitmap.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -113,8 +113,7 @@ static void resize_tmp(ASS_SynthPriv *pr
         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 @@ ASS_SynthPriv *ass_synth_init(double rad
 
 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 @@ static Bitmap *alloc_bitmap(int w, int h
 
 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)

Modified: trunk/libass/ass_drawing.c
==============================================================================
--- trunk/libass/ass_drawing.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_drawing.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -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 @@ static void drawing_evaluate_curve(ASS_D
  * \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 @@ ASS_Drawing *ass_drawing_new(void *fontc
     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 @@ FT_OutlineGlyph *ass_drawing_parse(ASS_D
     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;
 

Modified: trunk/libass/ass_drawing.h
==============================================================================
--- trunk/libass/ass_drawing.h	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_drawing.h	Wed Aug 11 03:14:37 2010	(r31956)
@@ -57,7 +57,9 @@ typedef struct {
     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 @@ typedef struct {
 } 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);

Modified: trunk/libass/ass_font.c
==============================================================================
--- trunk/libass/ass_font.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_font.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -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 @@ void ass_font_free(ASS_Font *font)
     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);
 }
 

Modified: trunk/libass/ass_fontconfig.c
==============================================================================
--- trunk/libass/ass_fontconfig.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_fontconfig.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -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 @@ int fontconfig_update(FCInstance *priv)
 
 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);
 }

Modified: trunk/libass/ass_library.c
==============================================================================
--- trunk/libass/ass_library.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_library.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -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_library_done(ASS_Library *priv)
 
 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 @@ void ass_set_style_overrides(ASS_Library
     if (priv->style_overrides) {
         for (p = priv->style_overrides; *p; ++p)
             free(*p);
-        free(priv->style_overrides);
     }
+    free(priv->style_overrides);
 
     if (!list)
         return;

Modified: trunk/libass/ass_parse.c
==============================================================================
--- trunk/libass/ass_parse.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_parse.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -214,13 +214,14 @@ static char *parse_vector_clip(ASS_Rende
 {
     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 @@ static char *parse_tag(ASS_Renderer *ren
             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")) {

Modified: trunk/libass/ass_render.c
==============================================================================
--- trunk/libass/ass_render.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_render.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -145,14 +145,13 @@ void ass_renderer_done(ASS_Renderer *ren
         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 @@ init_render_context(ASS_Renderer *render
     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 @@ ass_render_event(ASS_Renderer *render_pr
             drawing = render_priv->state.drawing =
                 ass_drawing_new(render_priv->fontconfig_priv,
                     render_priv->state.font,
-                    render_priv->settings.hinting,
                     render_priv->ftlibrary);
         }
     }

Modified: trunk/libass/ass_utils.c
==============================================================================
--- trunk/libass/ass_utils.c	Tue Aug 10 15:33:49 2010	(r31955)
+++ trunk/libass/ass_utils.c	Wed Aug 11 03:14:37 2010	(r31956)
@@ -25,6 +25,7 @@
 #include <inttypes.h>
 #include <ft2build.h>
 #include FT_GLYPH_H
+#include <strings.h>
 
 #include "ass_library.h"
 #include "ass.h"


More information about the MPlayer-cvslog mailing list