Copy font data to ass_library instead of referencing demuxer-owned memory.
authoreugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>
Mon, 7 Jan 2008 14:02:06 +0000 (14:02 +0000)
committereugeni <eugeni@b3059339-0415-0410-9bf9-f77b7e298cf2>
Mon, 7 Jan 2008 14:02:06 +0000 (14:02 +0000)
This fixes segfault when fonts are accessed after demuxer has been closed.

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

libass/ass.h
libass/ass_library.c

index b870544..e88d69d 100644 (file)
@@ -196,6 +196,11 @@ int ass_read_styles(ass_track_t* track, char* fname, char* codepage);
 void ass_add_font(ass_library_t* library, char* name, char* data, int data_size);
 
 /**
+ * \brief Remove all fonts stored in ass_library object
+ */
+void ass_clear_fonts(ass_library_t* library);
+
+/**
  * \brief Calculates timeshift from now to the start of some other subtitle event, depending on movement parameter
  * \param track subtitle track
  * \param now current time, ms
index 107a6ed..9c41c1d 100644 (file)
@@ -37,6 +37,7 @@ void ass_library_done(ass_library_t* priv)
        if (priv) {
                ass_set_fonts_dir(priv, NULL);
                ass_set_style_overrides(priv, NULL);
+               ass_clear_fonts(priv);
                free(priv);
        }
 }
@@ -84,10 +85,27 @@ static void grow_array(void **array, int nelem, size_t elsize)
 
 void ass_add_font(ass_library_t* priv, char* name, char* data, int size)
 {
+       int idx = priv->num_fontdata;
+       if (!name || !data || !size)
+               return;
        grow_array((void**)&priv->fontdata, priv->num_fontdata, sizeof(*priv->fontdata));
-       priv->fontdata[priv->num_fontdata].name = name;
-       priv->fontdata[priv->num_fontdata].data = data;
-       priv->fontdata[priv->num_fontdata].size = size;
+       
+       priv->fontdata[idx].name = malloc(strlen(name));
+       strcpy(priv->fontdata[idx].name, name);
+       
+       priv->fontdata[idx].data = malloc(size);
+       memcpy(priv->fontdata[idx].data, data, size);
+       
+       priv->fontdata[idx].size = size;
+       
        priv->num_fontdata ++;
 }
 
+void ass_clear_fonts(ass_library_t* priv)
+{
+       int i;
+       for (i = 0; i < priv->num_fontdata; ++i) {
+               free(priv->fontdata[i].name);
+               free(priv->fontdata[i].data);
+       }
+}