[Bf-blender-cvs] [ee37819cfba] cycles_texture_cache: Fix (unreported): 'CoInitializeEx' being called without 'CoUninitialize'

Germano Cavalcante noreply at git.blender.org
Thu May 6 11:25:39 CEST 2021


Commit: ee37819cfbadb504e70565a8da2efe9db6e5dc10
Author: Germano Cavalcante
Date:   Mon May 3 19:32:05 2021 -0300
Branches: cycles_texture_cache
https://developer.blender.org/rBee37819cfbadb504e70565a8da2efe9db6e5dc10

Fix (unreported): 'CoInitializeEx' being called without 'CoUninitialize'

Problem introduced in {rB1f223b9a}.

This was possibly causing random crashes in Blender file browser when
compiled with ASAN.

Microsoft documents indicate that any call to `CoInitializeEx` must be
balanced by a corresponding call to `CoUninitialize`.

https://docs.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializeex#remarks

===================================================================

M	source/blender/blenlib/intern/storage.c

===================================================================

diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index 287334a34ee..cb2634e6fda 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -299,12 +299,16 @@ bool BLI_file_alias_target(const char *filepath,
     return false;
   }
 
-  IShellLinkW *Shortcut = NULL;
-  bool success = false;
-  CoInitializeEx(NULL, COINIT_MULTITHREADED);
+  HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+  if (FAILED(hr)) {
+    return false;
+  }
 
-  HRESULT hr = CoCreateInstance(
+  IShellLinkW *Shortcut = NULL;
+  hr = CoCreateInstance(
       &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLinkW, (LPVOID *)&Shortcut);
+
+  bool success = false;
   if (SUCCEEDED(hr)) {
     IPersistFile *PersistFile;
     hr = Shortcut->lpVtbl->QueryInterface(Shortcut, &IID_IPersistFile, (LPVOID *)&PersistFile);
@@ -328,6 +332,7 @@ bool BLI_file_alias_target(const char *filepath,
     Shortcut->lpVtbl->Release(Shortcut);
   }
 
+  CoUninitialize();
   return (success && r_targetpath[0]);
 #  else
   UNUSED_VARS(r_targetpath, filepath);



More information about the Bf-blender-cvs mailing list