changeset 25613:f00333e3facf

Copy font data to ass_library instead of referencing demuxer-owned memory. This fixes segfault when fonts are accessed after demuxer has been closed.
author eugeni
date Mon, 07 Jan 2008 14:02:06 +0000
parents 6bee6b0eef6c
children cc740dcda27c
files libass/ass.h libass/ass_library.c
diffstat 2 files changed, 26 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libass/ass.h	Mon Jan 07 13:29:13 2008 +0000
+++ b/libass/ass.h	Mon Jan 07 14:02:06 2008 +0000
@@ -196,6 +196,11 @@
 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
--- a/libass/ass_library.c	Mon Jan 07 13:29:13 2008 +0000
+++ b/libass/ass_library.c	Mon Jan 07 14:02:06 2008 +0000
@@ -37,6 +37,7 @@
 	if (priv) {
 		ass_set_fonts_dir(priv, NULL);
 		ass_set_style_overrides(priv, NULL);
+		ass_clear_fonts(priv);
 		free(priv);
 	}
 }
@@ -84,10 +85,27 @@
 
 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);
+	}
+}