errno = b_errno_win32;
          return FALSE;
       }
-
       m_bCoInitializeCalled = true;
+   }
 
-      // Initialize COM security
+   // Initialize COM security
+   if (!m_bCoInitializeSecurityCalled) {
       hr =
          CoInitializeSecurity(
          NULL,                           //  Allow *all* VSS writers to communicate back!
          errno = b_errno_win32;
          return FALSE;
       }
+      m_bCoInitializeSecurityCalled = true;      
    }
    
    // Release the IVssBackupComponents interface 
 
 BOOL VSSClientGeneric::CloseBackup()
 {
-   if (!m_pVssObject) {
+   BOOL bRet = FALSE;
+   if (!m_pVssObject)
       errno = ENOSYS;
-      return FALSE;
-   }
+   else {
+      IVssBackupComponents* pVss = (IVssBackupComponents*) m_pVssObject;
+      CComPtr<IVssAsync>  pAsync;
+      
+      m_bBackupIsInitialized = false;
 
-   BOOL bRet = FALSE;
-   IVssBackupComponents* pVss = (IVssBackupComponents*) m_pVssObject;
-   CComPtr<IVssAsync>  pAsync;
-   
-   m_bBackupIsInitialized = false;
+      if (SUCCEEDED(pVss->BackupComplete(&pAsync))) {
+         // Waits for the async operation to finish and checks the result
+         WaitAndCheckForAsyncOperation(pAsync);
+         bRet = TRUE;     
+      } else {
+         errno = b_errno_win32;
+         pVss->AbortBackup();
+      }
 
-   if (SUCCEEDED(pVss->BackupComplete(&pAsync))) {
-     // Waits for the async operation to finish and checks the result
-     WaitAndCheckForAsyncOperation(pAsync);
-     bRet = TRUE;     
-   } else {
-      errno = b_errno_win32;
-      pVss->AbortBackup();
-   }
+      if (m_uidCurrentSnapshotSet != GUID_NULL) {
+         VSS_ID idNonDeletedSnapshotID = GUID_NULL;
+         LONG lSnapshots;
 
-   if (m_uidCurrentSnapshotSet != GUID_NULL) {
-      VSS_ID idNonDeletedSnapshotID = GUID_NULL;
-      LONG lSnapshots;
+         pVss->DeleteSnapshots(
+            m_uidCurrentSnapshotSet, 
+            VSS_OBJECT_SNAPSHOT_SET,
+            FALSE,
+            &lSnapshots,
+            &idNonDeletedSnapshotID);
 
-      pVss->DeleteSnapshots(
-         m_uidCurrentSnapshotSet, 
-         VSS_OBJECT_SNAPSHOT_SET,
-         FALSE,
-         &lSnapshots,
-         &idNonDeletedSnapshotID);
+         m_uidCurrentSnapshotSet = GUID_NULL;
+      }
 
-      m_uidCurrentSnapshotSet = GUID_NULL;
+      pVss->Release();
+      m_pVssObject = NULL;
    }
 
-
-   pVss->Release();
-   m_pVssObject = NULL;
+   // Call CoUninitialize if the CoInitialize was performed sucesfully
+   if (m_bCoInitializeCalled) {
+      CoUninitialize();
+      m_bCoInitializeCalled = false;
+   }
 
    return bRet;
 }