shithub: choc

Download patch

ref: 59f737ad1b32fafb6f21edcaa4dd79c3444a880a
parent: 173300a37bd820a17233645280838e4b1bfc5a79
author: Fabian Greffrath <[email protected]>
date: Mon Jan 28 04:34:12 EST 2019

txt: free already loaded libraries on LoadLibraryW() failure

This fixes a future "Resource leak" cppcheck error.

--- a/textscreen/txt_fileselect.c
+++ b/textscreen/txt_fileselect.c
@@ -175,11 +175,18 @@
 
 static int LoadDLLs(void)
 {
-    HMODULE comdlg32 = LoadLibraryW(L"comdlg32.dll");
-    HMODULE shell32 = LoadLibraryW(L"shell32.dll");
+    HMODULE comdlg32, shell32
 
-    if (comdlg32 == NULL || shell32 == NULL)
+    comdlg32 = LoadLibraryW(L"comdlg32.dll");
+    if (comdlg32 == NULL)
     {
+        return 0;
+    }
+
+    shell32 = LoadLibraryW(L"shell32.dll");
+    if (shell32 == NULL)
+    {
+        FreeLibrary(comdlg32);
         return 0;
     }