From 9960c105240438525b652fa258584113a710e20f Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 1 Sep 2022 07:17:59 +0200
Subject: [PATCH] skins2: fix usage of NULL config_GetUserDir/config_GetSysPath
 results

---
 modules/gui/skins2/os2/os2_factory.cpp     | 24 ++++++++++++++--------
 modules/gui/skins2/win32/win32_factory.cpp | 20 +++++++++++-------
 modules/gui/skins2/x11/x11_factory.cpp     | 14 +++++++++----
 3 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/modules/gui/skins2/os2/os2_factory.cpp b/modules/gui/skins2/os2/os2_factory.cpp
index 8e42262b9f68..462f463f7413 100644
--- a/modules/gui/skins2/os2/os2_factory.cpp
+++ b/modules/gui/skins2/os2/os2_factory.cpp
@@ -218,16 +218,22 @@ bool OS2Factory::init()
 
     // Initialize the resource path
     char *datadir = config_GetUserDir( VLC_USERDATA_DIR );
-    m_resourcePath.push_back( (std::string)datadir + "\\skins" );
-    free( datadir );
+    if (likely(datadir != nullptr))
+    {
+        m_resourcePath.push_back( (std::string)datadir + "\\skins" );
+        free( datadir );
+    }
     datadir = config_GetSysPath(VLC_PKG_DATA_DIR, NULL);
-    m_resourcePath.push_back( (std::string)datadir + "\\skins" );
-    m_resourcePath.push_back( (std::string)datadir + "\\skins2" );
-    m_resourcePath.push_back( (std::string)datadir + "\\share\\skins" );
-    m_resourcePath.push_back( (std::string)datadir + "\\share\\skins2" );
-    m_resourcePath.push_back( (std::string)datadir + "\\vlc\\skins" );
-    m_resourcePath.push_back( (std::string)datadir + "\\vlc\\skins2" );
-    free( datadir );
+    if (likely(datadir != nullptr))
+    {
+        m_resourcePath.push_back( (std::string)datadir + "\\skins" );
+        m_resourcePath.push_back( (std::string)datadir + "\\skins2" );
+        m_resourcePath.push_back( (std::string)datadir + "\\share\\skins" );
+        m_resourcePath.push_back( (std::string)datadir + "\\share\\skins2" );
+        m_resourcePath.push_back( (std::string)datadir + "\\vlc\\skins" );
+        m_resourcePath.push_back( (std::string)datadir + "\\vlc\\skins2" );
+        free( datadir );
+    }
 
     // All went well
     return true;
diff --git a/modules/gui/skins2/win32/win32_factory.cpp b/modules/gui/skins2/win32/win32_factory.cpp
index 8c0ca0631b53..cf9d4657a6eb 100644
--- a/modules/gui/skins2/win32/win32_factory.cpp
+++ b/modules/gui/skins2/win32/win32_factory.cpp
@@ -232,14 +232,20 @@ bool Win32Factory::init()
 
     // Initialize the resource path
     char *datadir = config_GetUserDir( VLC_USERDATA_DIR );
-    m_resourcePath.push_back( (std::string)datadir + "\\skins" );
-    free( datadir );
+    if (likely(datadir != nullptr))
+    {
+        m_resourcePath.push_back( (std::string)datadir + "\\skins" );
+        free( datadir );
+    }
     datadir = config_GetSysPath(VLC_PKG_DATA_DIR, NULL);
-    m_resourcePath.push_back( (std::string)datadir + "\\skins" );
-    m_resourcePath.push_back( (std::string)datadir + "\\skins2" );
-    m_resourcePath.push_back( (std::string)datadir + "\\share\\skins" );
-    m_resourcePath.push_back( (std::string)datadir + "\\share\\skins2" );
-    free( datadir );
+    if (likely(datadir != nullptr))
+    {
+        m_resourcePath.push_back( (std::string)datadir + "\\skins" );
+        m_resourcePath.push_back( (std::string)datadir + "\\skins2" );
+        m_resourcePath.push_back( (std::string)datadir + "\\share\\skins" );
+        m_resourcePath.push_back( (std::string)datadir + "\\share\\skins2" );
+        free( datadir );
+    }
 
     // Enumerate all monitors available
     EnumDisplayMonitors( NULL, NULL, MonitorEnumProc, (LPARAM)&m_monitorList );
diff --git a/modules/gui/skins2/x11/x11_factory.cpp b/modules/gui/skins2/x11/x11_factory.cpp
index f1e0a46f6bc0..6d0fc69464f2 100644
--- a/modules/gui/skins2/x11/x11_factory.cpp
+++ b/modules/gui/skins2/x11/x11_factory.cpp
@@ -85,12 +85,18 @@ bool X11Factory::init()
 
     // Initialize the resource path
     char *datadir = config_GetUserDir( VLC_USERDATA_DIR );
-    m_resourcePath.push_back( (std::string)datadir + "/skins2" );
-    free( datadir );
+    if (likely(datadir != nullptr))
+    {
+        m_resourcePath.push_back( (std::string)datadir + "/skins2" );
+        free( datadir );
+    }
     m_resourcePath.push_back( (std::string)"share/skins2" );
     datadir = config_GetSysPath(VLC_PKG_DATA_DIR, "skins2");
-    m_resourcePath.push_back( (std::string)datadir );
-    free( datadir );
+    if (likely(datadir != nullptr))
+    {
+        m_resourcePath.push_back( (std::string)datadir );
+        free( datadir );
+    }
 
     // Determine the monitor geometry
     getDefaultGeometry( &m_screenWidth, &m_screenHeight );
-- 
GitLab