From e8e407dfba95f08558770cd67c77123a03b4f4e1 Mon Sep 17 00:00:00 2001
From: Marek Roszko <mark.roszko@gmail.com>
Date: Mon, 13 Feb 2023 20:04:55 -0500
Subject: [PATCH] It's not impossible for the font face to fail loading

LoadFont()'s only usage already checked for nullptr to fallback, let's actually return nullptr on a failed load

Fixes sentry KICAD-8Z
Make the cause of sentry KICAD-95
---
 common/font/outline_font.cpp | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp
index 080fe408de..6929822a54 100644
--- a/common/font/outline_font.cpp
+++ b/common/font/outline_font.cpp
@@ -90,26 +90,29 @@ wxString OUTLINE_FONT::FontLibraryVersion()
 
 OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, bool aItalic )
 {
-    OUTLINE_FONT* font = new OUTLINE_FONT();
+    std::unique_ptr<OUTLINE_FONT> font = std::make_unique<OUTLINE_FONT>();
 
     wxString fontFile;
     using fc = fontconfig::FONTCONFIG;
 
     fc::FF_RESULT retval = Fontconfig()->FindFont( aFontName, fontFile, aBold, aItalic );
 
+    if( retval == fc::FF_RESULT::FF_ERROR )
+        return nullptr;
+
     if( retval == fc::FF_RESULT::FF_MISSING_BOLD || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
         font->SetFakeBold();
 
     if( retval == fc::FF_RESULT::FF_MISSING_ITAL || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL )
         font->SetFakeItal();
 
-    if( retval != fc::FF_RESULT::FF_ERROR )
-        (void) font->loadFace( fontFile );
+    if( font->loadFace( fontFile ) != 0 )
+        return nullptr;
 
     font->m_fontName = aFontName;       // Keep asked-for name, even if we substituted.
     font->m_fontFileName = fontFile;
 
-    return font;
+    return font.release();
 }