[MPlayer-cvslog] r19213 - trunk/libvo/font_load_ft.c

reimar subversion at mplayerhq.hu
Fri Jul 28 15:50:08 CEST 2006


Author: reimar
Date: Fri Jul 28 15:50:08 2006
New Revision: 19213

Modified:
   trunk/libvo/font_load_ft.c

Log:
Avoid large amounts of data on the stack (> 900k on 64 bit systems).
Patch by Tobias Diedrich (ranma at tdiedrich de) with minor modifications by me.


Modified: trunk/libvo/font_load_ft.c
==============================================================================
--- trunk/libvo/font_load_ft.c	(original)
+++ trunk/libvo/font_load_ft.c	Fri Jul 28 15:50:08 2006
@@ -955,12 +955,12 @@
 
 font_desc_t* read_font_desc_ft(const char *fname, int movie_width, int movie_height)
 {
-    font_desc_t *desc;
+    font_desc_t *desc = NULL;
 
     FT_Face face;
 
-    FT_ULong my_charset[MAX_CHARSET_SIZE]; /* characters we want to render; Unicode */
-    FT_ULong my_charcodes[MAX_CHARSET_SIZE]; /* character codes in 'encoding' */
+    FT_ULong *my_charset = malloc(MAX_CHARSET_SIZE * sizeof(FT_ULong)); /* characters we want to render; Unicode */
+    FT_ULong *my_charcodes = malloc(MAX_CHARSET_SIZE * sizeof(FT_ULong)); /* character codes in 'encoding' */
 
     char *charmap = "ucs-4";
     int err;
@@ -973,6 +973,11 @@
     float subtitle_font_ppem;
     float osd_font_ppem;
 
+    if (my_charset == NULL || my_charcodes == NULL) {
+	mp_msg(MSGT_OSD, MSGL_ERR, "subtitle font: malloc failed.\n");
+	goto err_out;
+    }
+
     switch (subtitle_autoscale) {
     case 1:
 	movie_size = movie_height;
@@ -1005,7 +1010,7 @@
     }
 
     desc = init_font_desc();
-    if(!desc) return NULL;
+    if(!desc) goto err_out;
 
 //    t=GetTimer();
 
@@ -1030,11 +1035,10 @@
 
     if (charset_size < 0) {
 	mp_msg(MSGT_OSD, MSGL_ERR, "subtitle font: prepare_charset failed.\n");
-	free_font_desc(desc);
-	return NULL;
+	goto err_out;
     }
 #else
-    return NULL;
+    goto err_out;
 #endif
 
 //    fprintf(stderr, "fg: prepare t = %lf\n", GetTimer()-t);
@@ -1045,8 +1049,7 @@
 
     if (err) {
 	mp_msg(MSGT_OSD, MSGL_ERR, "Cannot prepare subtitle font.\n");
-	free_font_desc(desc);
-	return NULL;
+	goto err_out;
     }
 
 gen_osd:
@@ -1054,8 +1057,7 @@
     /* generate the OSD font */
     err = load_osd_face(&face);
     if (err) {
-	free_font_desc(desc);
-	return NULL;
+	goto err_out;
     }
     desc->face_cnt++;
 
@@ -1065,16 +1067,14 @@
     
     if (err) {
 	mp_msg(MSGT_OSD, MSGL_ERR, "Cannot prepare OSD font.\n");
-	free_font_desc(desc);
-	return NULL;
+	goto err_out;
     }
 
     err = generate_tables(desc, subtitle_font_thickness, subtitle_font_radius);
     
     if (err) {
 	mp_msg(MSGT_OSD, MSGL_ERR, "Cannot generate tables.\n");
-	free_font_desc(desc);
-	return NULL;
+	goto err_out;
     }
 
     // final cleanup
@@ -1092,7 +1092,16 @@
 	    desc->font[i] = desc->font[j];
 	}
     }
+    free(my_charset);
+    free(my_charcodes);
     return desc;
+
+err_out:
+    if (desc)
+      free_font_desc(desc);
+    free(my_charset);
+    free(my_charcodes);
+    return NULL;
 }
 
 int init_freetype(void)



More information about the MPlayer-cvslog mailing list