Import libass 0.9.11
authorgreg <greg@b3059339-0415-0410-9bf9-f77b7e298cf2>
Wed, 11 Aug 2010 01:14:37 +0000 (01:14 +0000)
committergreg <greg@b3059339-0415-0410-9bf9-f77b7e298cf2>
Wed, 11 Aug 2010 01:14:37 +0000 (01:14 +0000)
This version fixes a (sometimes pretty bad) memory leak.

git-svn-id: svn://git.mplayerhq.hu/mplayer/trunk@31956 b3059339-0415-0410-9bf9-f77b7e298cf2

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

index 7dcde34..cc66e1a 100644 (file)
@@ -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 *track, char *str)
     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;
index 1d98298..4592c52 100644 (file)
@@ -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.
index 9211a7c..522bce7 100644 (file)
@@ -113,8 +113,7 @@ static void resize_tmp(ASS_SynthPriv *priv, int w, int h)
         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 radius)
 
 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)
index 7833c10..93cc458 100644 (file)
  * \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_Drawing *drawing,
  * \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 *fontconfig_priv, ASS_Font *font,
     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_Drawing *drawing, int raw_mode)
     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;
 
index 0223271..f677fcd 100644 (file)
@@ -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);
index 6a1faab..0b061bf 100644 (file)
@@ -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);
 }
 
index 15490d5..031f4fa 100644 (file)
@@ -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);
 }
index 53b91af..13b5dab 100644 (file)
@@ -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 *priv, char **list)
     if (priv->style_overrides) {
         for (p = priv->style_overrides; *p; ++p)
             free(*p);
-        free(priv->style_overrides);
     }
+    free(priv->style_overrides);
 
     if (!list)
         return;
index 654fa7f..776416d 100644 (file)
@@ -214,13 +214,14 @@ static char *parse_vector_clip(ASS_Renderer *render_priv, char *p)
 {
     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 *render_priv, char *p, double pwr)
             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")) {
index 3e241c1..c960776 100644 (file)
@@ -145,14 +145,13 @@ void ass_renderer_done(ASS_Renderer *render_priv)
         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_priv, ASS_Event *event)
     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_priv, ASS_Event *event,
             drawing = render_priv->state.drawing =
                 ass_drawing_new(render_priv->fontconfig_priv,
                     render_priv->state.font,
-                    render_priv->settings.hinting,
                     render_priv->ftlibrary);
         }
     }
index 59fdbdf..47b898f 100644 (file)
@@ -25,6 +25,7 @@
 #include <inttypes.h>
 #include <ft2build.h>
 #include FT_GLYPH_H
+#include <strings.h>
 
 #include "ass_library.h"
 #include "ass.h"