From 8a88253e3f8d7faefa6c58ae937b124e1ac69c54 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 31 Aug 2015 11:56:15 +0200 Subject: [PATCH] fontselect: fix a memory leak The result of the subst_font callback was not freed. --- libass/ass_fontselect.c | 51 +++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/libass/ass_fontselect.c b/libass/ass_fontselect.c index 6441caa..dc143c4 100644 --- a/libass/ass_fontselect.c +++ b/libass/ass_fontselect.c @@ -502,13 +502,17 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library, if (!priv->n_font) return NULL; + ASS_FontProviderMetaData default_meta = { + .n_fullname = 1, + .fullnames = &family_trim, + }; + // get a list of substitutes if applicable, and use it for matching if (default_provider && default_provider->funcs.subst_font) { default_provider->funcs.subst_font(default_provider->priv, family_trim, &meta); } if (!meta.n_fullname) { - meta.n_fullname = 1; - meta.fullnames = &family_trim; + meta = default_meta; } // fill font request @@ -561,29 +565,32 @@ static char *select_font(ASS_FontSelector *priv, ASS_Library *library, } } - // free font name - free(family_trim); - // found anything? - if (!selected) { - return NULL; + char *result = NULL; + if (selected) { + // successfully matched, set up return values + *postscript_name = selected->postscript_name; + *index = selected->index; + *uid = selected->uid; + + // set up memory stream if there is no path + if (selected->path == NULL) { + ASS_FontProvider *provider = selected->provider; + stream->func = provider->funcs.get_data; + stream->priv = selected->priv; + // FIXME: we should define a default family name in some way, + // possibly the first (or last) English name + result = strdup(selected->families[0]); + } else + result = strdup(selected->path); + } + + free(family_trim); + if (meta.fullnames != default_meta.fullnames) { + free(meta.fullnames); } - // successfully matched, set up return values - *postscript_name = selected->postscript_name; - *index = selected->index; - *uid = selected->uid; - - // set up memory stream if there is no path - if (selected->path == NULL) { - ASS_FontProvider *provider = selected->provider; - stream->func = provider->funcs.get_data; - stream->priv = selected->priv; - // FIXME: we should define a default family name in some way, - // possibly the first (or last) English name - return strdup(selected->families[0]); - } else - return strdup(selected->path); + return result; } -- 2.40.0