[MPlayer-dev-eng] [PATCH] fix stack usage in libvo/font_load_ft.c
Tobias Diedrich
ranma at tdiedrich.de
Fri Jul 21 22:34:22 CEST 2006
read_font_desc_ft allocates ~1MB on the stack on amd64
(MAX_CHARSET_SIZE is 60000 and sizeof(FT_ULong) is 8).
This seems a bit unreasonable to me.
The following patch changes it to malloc the memory instead.
--
Tobias PGP: http://9ac7e0bc.uguu.de
-------------- next part --------------
Index: mplayer/libvo/font_load_ft.c
===================================================================
--- mplayer/libvo/font_load_ft.c (revision 19150)
+++ mplayer/libvo/font_load_ft.c (working copy)
@@ -958,8 +958,8 @@
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;
@@ -1004,7 +1004,11 @@
}
desc = init_font_desc();
- if(!desc) return NULL;
+ if(!desc) {
+ free(my_charset);
+ free(my_charcodes);
+ return NULL;
+ }
// t=GetTimer();
@@ -1030,9 +1034,14 @@
if (charset_size < 0) {
mp_msg(MSGT_OSD, MSGL_ERR, "subtitle font: prepare_charset failed.\n");
free_font_desc(desc);
+ free(my_charset);
+ free(my_charcodes);
return NULL;
}
#else
+ free_font_desc(desc);
+ free(my_charset);
+ free(my_charcodes);
return NULL;
#endif
@@ -1045,6 +1054,8 @@
if (err) {
mp_msg(MSGT_OSD, MSGL_ERR, "Cannot prepare subtitle font.\n");
free_font_desc(desc);
+ free(my_charset);
+ free(my_charcodes);
return NULL;
}
@@ -1054,6 +1065,8 @@
err = load_osd_face(&face);
if (err) {
free_font_desc(desc);
+ free(my_charset);
+ free(my_charcodes);
return NULL;
}
desc->face_cnt++;
@@ -1065,6 +1078,8 @@
if (err) {
mp_msg(MSGT_OSD, MSGL_ERR, "Cannot prepare OSD font.\n");
free_font_desc(desc);
+ free(my_charset);
+ free(my_charcodes);
return NULL;
}
@@ -1073,6 +1088,8 @@
if (err) {
mp_msg(MSGT_OSD, MSGL_ERR, "Cannot generate tables.\n");
free_font_desc(desc);
+ free(my_charset);
+ free(my_charcodes);
return NULL;
}
@@ -1091,6 +1108,8 @@
desc->font[i] = desc->font[j];
}
}
+ free(my_charset);
+ free(my_charcodes);
return desc;
}
More information about the MPlayer-dev-eng
mailing list