Index: TortoiseShell/PIDL.cpp
===================================================================
--- TortoiseShell/PIDL.cpp	(revision 21697)
+++ TortoiseShell/PIDL.cpp	(working copy)
@@ -19,12 +19,13 @@
 #include "stdafx.h"
 #include "PIDL.h"
 
-PIDL::PIDL()
+PIDL::PIDL() : malloc_(0)
 {
     ::SHGetMalloc(&malloc_);
 }
 
 PIDL::~PIDL()
 {
-    malloc_->Release();
+    if (malloc_ != 0)
+        malloc_->Release();
 }
Index: Utils/CommonAppUtils.cpp
===================================================================
--- Utils/CommonAppUtils.cpp	(revision 21697)
+++ Utils/CommonAppUtils.cpp	(working copy)
@@ -694,22 +694,22 @@
 
     CAutoLibrary hShell = LoadLibrary(_T("Shell32.dll"));
 
-    if (hShell)
+    if (!hShell.IsValid())
+        return;
+
+    SHGPSFW pfnSHGPSFW = (SHGPSFW)::GetProcAddress(hShell, "SHGetPropertyStoreForWindow");
+    if (pfnSHGPSFW == 0)
+         return;
+
+    IPropertyStore *pps = 0;
+    HRESULT hr = pfnSHGPSFW(hWnd, IID_PPV_ARGS(&pps));
+    if (SUCCEEDED(hr))
     {
-        SHGPSFW pfnSHGPSFW = (SHGPSFW)::GetProcAddress(hShell, "SHGetPropertyStoreForWindow");
-        if (pfnSHGPSFW)
-        {
-            IPropertyStore *pps;
-            HRESULT hr = pfnSHGPSFW(hWnd, IID_PPV_ARGS(&pps));
-            if (SUCCEEDED(hr))
-            {
-                PROPVARIANT var;
-                var.vt = VT_BOOL;
-                var.boolVal = VARIANT_TRUE;
-                hr = pps->SetValue(PKEY_AppUserModel_PreventPinning, var);
-                pps->Release();
-            }
-        }
+        PROPVARIANT var;
+        var.vt = VT_BOOL;
+        var.boolVal = VARIANT_TRUE;
+        hr = pps->SetValue(PKEY_AppUserModel_PreventPinning, var);
+        pps->Release();
     }
 }
 
Index: Utils/MiscUI/BrowseFolder.cpp
===================================================================
--- Utils/MiscUI/BrowseFolder.cpp	(revision 21697)
+++ Utils/MiscUI/BrowseFolder.cpp	(working copy)
@@ -161,7 +161,7 @@
                 }
                 psiResult->Release();
 
-                IFileDialogCustomize *  pfdCustomize;
+                IFileDialogCustomize* pfdCustomize = 0;
                 hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
                 if (SUCCEEDED(hr))
                 {
@@ -180,10 +180,7 @@
     }
     else
     {
-        LPITEMIDLIST itemIDList;
-
-        BROWSEINFO browseInfo;
-
+        BROWSEINFO browseInfo       = {};
         browseInfo.hwndOwner        = parent;
         browseInfo.pidlRoot         = m_root;
         browseInfo.pszDisplayName   = m_displayName;
@@ -197,7 +194,7 @@
             browseInfo.lpfn = BrowseCallBackProc;
         }
 
-        itemIDList = SHBrowseForFolder(&browseInfo);
+        LPITEMIDLIST itemIDList = SHBrowseForFolder(&browseInfo);
 
         //is the dialog canceled?
         if (!itemIDList)
@@ -210,11 +207,8 @@
 
             path.ReleaseBuffer();
 
-            LPMALLOC    shellMalloc;
-            HRESULT     hr;
-
-            hr = SHGetMalloc(&shellMalloc);
-
+            LPMALLOC shellMalloc = 0;
+            HRESULT hr = SHGetMalloc(&shellMalloc);
             if (SUCCEEDED(hr))
             {
                 //free memory
Index: Utils/Win7.h
===================================================================
--- Utils/Win7.h	(revision 21697)
+++ Utils/Win7.h	(working copy)
@@ -1238,7 +1238,7 @@
     if (ppv == 0)
         return E_POINTER;
     *ppv = NULL;
-    IShellLibrary *plib;
+    IShellLibrary *plib = 0;
     HRESULT hr = CoCreateInstance(CLSID_ShellLibrary, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&plib));
     if (SUCCEEDED(hr))
     {
@@ -1257,7 +1257,7 @@
     if (ppv == 0)
         return E_POINTER;
     *ppv = NULL;
-    IShellLibrary *plib;
+    IShellLibrary *plib = 0;
     HRESULT hr = CoCreateInstance(CLSID_ShellLibrary, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&plib));
     if (SUCCEEDED(hr))
     {
@@ -1288,6 +1288,8 @@
 
 __inline HRESULT SHAddFolderPathToLibrary(__in IShellLibrary *plib, __in PCWSTR pszFolderPath)
 {
+    if(plib == 0)
+        return E_INVALIDARG;
     IShellItem *psiFolder = NULL;
     HRESULT hr = SHCreateItemFromParsingName(pszFolderPath, NULL, IID_PPV_ARGS(&psiFolder));
     if (SUCCEEDED(hr))
@@ -1300,11 +1302,14 @@
 
 __inline HRESULT SHRemoveFolderPathFromLibrary(__in IShellLibrary *plib, __in PCWSTR pszFolderPath)
 {
+    if(plib == 0)
+        return E_INVALIDARG;
+
     PIDLIST_ABSOLUTE pidlFolder = SHSimpleIDListFromPath(pszFolderPath);
     HRESULT hr = pidlFolder ? S_OK : E_INVALIDARG;
     if (SUCCEEDED(hr))
     {
-        IShellItem *psiFolder;
+        IShellItem *psiFolder = 0;
         hr = SHCreateItemFromIDList(pidlFolder, IID_PPV_ARGS(&psiFolder));
         if (SUCCEEDED(hr))
         {
@@ -1320,6 +1325,8 @@
 {
     if (ppszResolvedPath == 0)
         return E_POINTER;
+    if(plib == 0)
+        return E_INVALIDARG;
 
     *ppszResolvedPath = NULL;
     PIDLIST_ABSOLUTE pidlFolder = SHSimpleIDListFromPath(pszFolderPath);
@@ -1346,6 +1353,9 @@
 
 __inline HRESULT SHSaveLibraryInFolderPath(__in IShellLibrary *plib, __in PCWSTR pszFolderPath, __in PCWSTR pszLibraryName, __in LIBRARYSAVEFLAGS lsf, __deref_opt_out PWSTR *ppszSavedToPath)
 {
+    if(plib == 0)
+        return E_INVALIDARG;
+
     if (ppszSavedToPath)
     {
         *ppszSavedToPath = NULL;
