[Pkg-owncloud-commits] [owncloud-client] 30/164: shell_integration: Fix a crash on explorer startup

Sandro Knauß hefee-guest at moszumanska.debian.org
Sun Mar 22 11:56:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit c6442f67c16b1be0f7b8cf2b8614e9b441ee2c88
Author: Jocelyn Turcotte <jturcotte at woboq.com>
Date:   Wed Feb 18 17:19:59 2015 +0100

    shell_integration: Fix a crash on explorer startup
    
    There is a race condition that can initialize the RemotePathChecker
    instance concurrently on the same address and cause a crash when locking
    the mutex. The reason is that local static initialization is not
    thread-safe with MSVC2013.
    
    Fix the issue by using call_once to initialize a static unique_ptr
    instead.
    
    This could be related to some reports of issue #2836.
---
 binary                                             |  2 +-
 shell_integration/windows/OCOverlays/OCOverlay.cpp | 35 ++++++++++++----------
 shell_integration/windows/OCOverlays/OCOverlay.h   |  6 ----
 3 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/binary b/binary
index 5a664de..01d7396 160000
--- a/binary
+++ b/binary
@@ -1 +1 @@
-Subproject commit 5a664de4d3ac2b6edb6a16edbb5e376724e64e76
+Subproject commit 01d73965dc8b862d1b2310d3ef801c297b697ec7
diff --git a/shell_integration/windows/OCOverlays/OCOverlay.cpp b/shell_integration/windows/OCOverlays/OCOverlay.cpp
index cc60357..dbff7e3 100644
--- a/shell_integration/windows/OCOverlays/OCOverlay.cpp
+++ b/shell_integration/windows/OCOverlays/OCOverlay.cpp
@@ -28,6 +28,7 @@
 #include <algorithm>
 #include <iostream>
 #include <fstream>
+#include <memory>
 
 using namespace std;
 
@@ -38,9 +39,24 @@ extern HINSTANCE instanceHandle;
 #define IDM_DISPLAY 0  
 #define IDB_OK 101
 
+namespace {
+
+unique_ptr<RemotePathChecker> s_instance;
+
+RemotePathChecker *getGlobalChecker()
+{
+	// On Vista we'll run into issue #2680 if we try to create the thread+pipe connection
+	// on any DllGetClassObject of our registered classes.
+	// Work around the issue by creating the static RemotePathChecker only once actually needed.
+	static once_flag s_onceFlag;
+	call_once(s_onceFlag, [] { s_instance.reset(new RemotePathChecker); });
+
+	return s_instance.get();
+}
+
+}
 OCOverlay::OCOverlay(int state) 
 	: _referenceCount(1)
-	, _checker(nullptr)
 	, _state(state)
 {
 }
@@ -49,16 +65,6 @@ OCOverlay::~OCOverlay(void)
 {
 }
 
-void OCOverlay::lazyInit()
-{
-	// On Vista we'll run into issue #2680 if we try to create the thread+pipe connection
-	// on any DllGetClassObject of our registered classes.
-	// Work around the issue by creating the static RemotePathChecker only once actually needed.
-	if (_checker)
-		return;
-	static RemotePathChecker s_remotePathChecker;
-	_checker = &s_remotePathChecker;
-}
 
 IFACEMETHODIMP_(ULONG) OCOverlay::AddRef()
 {
@@ -128,9 +134,8 @@ IFACEMETHODIMP OCOverlay::GetPriority(int *pPriority)
 
  IFACEMETHODIMP OCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib)
 {
-	lazyInit();
-	assert(_checker);
-	auto watchedDirectories = _checker->WatchedDirectories();
+	RemotePathChecker* checker = getGlobalChecker();
+	auto watchedDirectories = checker->WatchedDirectories();
 
 	wstring wpath(pwszPath);
 	wpath.append(L"\\");
@@ -147,7 +152,7 @@ IFACEMETHODIMP OCOverlay::GetPriority(int *pPriority)
 	}
 
 	int state = 0;
-	if (!_checker->IsMonitoredPath(pwszPath, &state)) {
+	if (!checker->IsMonitoredPath(pwszPath, &state)) {
 		return MAKE_HRESULT(S_FALSE, 0, 0);
 	}
 	return MAKE_HRESULT(state == _state ? S_OK : S_FALSE, 0, 0);
diff --git a/shell_integration/windows/OCOverlays/OCOverlay.h b/shell_integration/windows/OCOverlays/OCOverlay.h
index 3186807..39d2cb9 100644
--- a/shell_integration/windows/OCOverlays/OCOverlay.h
+++ b/shell_integration/windows/OCOverlays/OCOverlay.h
@@ -17,8 +17,6 @@
 
 #pragma once
 
-class RemotePathChecker;
-
 class OCOverlay : public IShellIconOverlayIdentifier
 
 {
@@ -36,12 +34,8 @@ protected:
     ~OCOverlay();
 
 private:
-	//bool _GenerateMessage(const wchar_t*, std::wstring*);
-	void lazyInit();
-
 	bool _IsOverlaysEnabled();
     long _referenceCount;
-	RemotePathChecker* _checker;
 	int _state;
 };
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list