[MPlayer-cvslog] r25641 - in trunk/libass: ass.h ass_library.c
eugeni
subversion at mplayerhq.hu
Mon Jan 7 15:02:06 CET 2008
Author: eugeni
Date: Mon Jan 7 15:02:06 2008
New Revision: 25641
Log:
Copy font data to ass_library instead of referencing demuxer-owned memory.
This fixes segfault when fonts are accessed after demuxer has been closed.
Modified:
trunk/libass/ass.h
trunk/libass/ass_library.c
Modified: trunk/libass/ass.h
==============================================================================
--- trunk/libass/ass.h (original)
+++ trunk/libass/ass.h Mon Jan 7 15:02:06 2008
@@ -196,6 +196,11 @@ int ass_read_styles(ass_track_t* track,
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
Modified: trunk/libass/ass_library.c
==============================================================================
--- trunk/libass/ass_library.c (original)
+++ trunk/libass/ass_library.c Mon Jan 7 15:02:06 2008
@@ -37,6 +37,7 @@ void ass_library_done(ass_library_t* pri
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
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);
+ }
+}
More information about the MPlayer-cvslog
mailing list