[vlc-commits] freetype/darwin: fix error path when font lookup fails

Felix Paul Kühne git at videolan.org
Tue Nov 24 18:30:29 CET 2015


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Tue Nov 24 18:10:29 2015 +0100| [3c166d67469f4398621900771453a1bfce99af76] | committer: Felix Paul Kühne

freetype/darwin: fix error path when font lookup fails

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3c166d67469f4398621900771453a1bfce99af76
---

 modules/text_renderer/freetype/fonts/darwin.c |   34 ++++++++++++++++++-------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/modules/text_renderer/freetype/fonts/darwin.c b/modules/text_renderer/freetype/fonts/darwin.c
index bd3b3ff..5225028 100644
--- a/modules/text_renderer/freetype/fonts/darwin.c
+++ b/modules/text_renderer/freetype/fonts/darwin.c
@@ -72,6 +72,8 @@ void addNewFontToFamily(filter_t *p_filter, CTFontDescriptorRef iter, char *path
 
 #ifndef NDEBUG
     msg_Dbg(p_filter, "New font: bold %i italic %i path '%s'", b_bold, b_italic, path);
+#else
+    VLC_UNUSED(p_filter);
 #endif
     NewFont(path, 0, b_bold, b_italic, p_family);
 
@@ -98,11 +100,8 @@ const vlc_family_t *CoreText_GetFamily(filter_t *p_filter, const char *psz_famil
         return p_family;
     }
 
-    /* create a new family object */
-    p_family = NewFamily(p_filter, psz_lc, &p_sys->p_families, &p_sys->family_map, psz_lc);
-    if (unlikely(!p_family)) {
-        return NULL;
-    }
+    CTFontCollectionRef coreTextFontCollection = NULL;
+    CFArrayRef matchedFontDescriptions = NULL;
 
     /* we search for family name, display name and name to find them all */
     const size_t numberOfAttributes = 3;
@@ -131,14 +130,26 @@ const vlc_family_t *CoreText_GetFamily(filter_t *p_filter, const char *psz_famil
                                                             (const void **)&coreTextFontDescriptors,
                                                             numberOfAttributes, NULL);
 
-    CTFontCollectionRef coreTextFontCollection = CTFontCollectionCreateWithFontDescriptors(coreTextFontDescriptorsArray, 0);
+    coreTextFontCollection = CTFontCollectionCreateWithFontDescriptors(coreTextFontDescriptorsArray, 0);
+    if (coreTextFontCollection == NULL) {
+        goto end;
+    }
 
-    CFArrayRef matchedFontDescriptions = CTFontCollectionCreateMatchingFontDescriptors(coreTextFontCollection);
+    matchedFontDescriptions = CTFontCollectionCreateMatchingFontDescriptors(coreTextFontCollection);
+    if (matchedFontDescriptions == NULL) {
+        goto end;
+    }
 
     CFIndex numberOfFoundFontDescriptions = CFArrayGetCount(matchedFontDescriptions);
 
     char *path = NULL;
 
+    /* create a new family object */
+    p_family = NewFamily(p_filter, psz_lc, &p_sys->p_families, &p_sys->family_map, psz_lc);
+    if (unlikely(!p_family)) {
+        goto end;
+    }
+
     for (CFIndex i = 0; i < numberOfFoundFontDescriptions; i++) {
         CTFontDescriptorRef iter = CFArrayGetValueAtIndex(matchedFontDescriptions, i);
         path = getPathForFontDescription(iter);
@@ -154,8 +165,13 @@ const vlc_family_t *CoreText_GetFamily(filter_t *p_filter, const char *psz_famil
         addNewFontToFamily(p_filter, iter, path, p_family);
     }
 
-    CFRelease(matchedFontDescriptions);
-    CFRelease(coreTextFontCollection);
+end:
+    if (matchedFontDescriptions != NULL) {
+        CFRelease(matchedFontDescriptions);
+    }
+    if (coreTextFontCollection != NULL) {
+        CFRelease(coreTextFontCollection);
+    }
 
     for (size_t x = 0; x < numberOfAttributes; x++) {
         CFRelease(coreTextAttributes[x]);



More information about the vlc-commits mailing list