Index: src/TortoiseShell/PreserveChdir.cpp
===================================================================
--- src/TortoiseShell/PreserveChdir.cpp	(revision 19653)
+++ src/TortoiseShell/PreserveChdir.cpp	(working copy)
@@ -19,33 +19,34 @@
 #include "stdafx.h"
 #include "PreserveChdir.h"
 
-PreserveChdir::PreserveChdir()
+PreserveChdir::PreserveChdir() :
+    size(GetCurrentDirectory(0, NULL)),
+    originalCurrentDirectory(size)
 {
-    DWORD len = GetCurrentDirectory(0, NULL);
-    if (len)
-    {
-        originalCurrentDirectory.reset (len);
-        if (GetCurrentDirectory(len, originalCurrentDirectory) !=0)
-            return;
-    }
+    if (size > 0)
+        if (GetCurrentDirectory(size, originalCurrentDirectory) !=0)
+            return; // succeeded
 
+    // GetCurrentDirectory failed
     originalCurrentDirectory.reset();
 }
 
 PreserveChdir::~PreserveChdir()
 {
-    if (originalCurrentDirectory)
-    {
-        DWORD len = GetCurrentDirectory(0, NULL);
-        auto_buffer<TCHAR> currentDirectory (len);
+    if (!originalCurrentDirectory)
+        return; // nothing to do
 
-        // _tchdir is an expensive function - don't call it unless we really have to
-        GetCurrentDirectory(len, currentDirectory);
-        if(_tcscmp(currentDirectory, originalCurrentDirectory) != 0)
-        {
-            SetCurrentDirectory(originalCurrentDirectory);
-        }
+    // _tchdir is an expensive function - don't call it unless we really have to
+    const DWORD len = GetCurrentDirectory(0, NULL);
+    if(len == size) {
+        // same size, must check contents
+        auto_buffer<TCHAR> currentDirectory(len);
+        if(GetCurrentDirectory(len, currentDirectory) != 0)
+            if(_tcscmp(currentDirectory, originalCurrentDirectory) == 0)
+                return; // no change required, reset of no use as dtor is called exactly once
+    }
 
+    // must reset directory
+    if(SetCurrentDirectory(originalCurrentDirectory))
         originalCurrentDirectory.reset();
-    }
 }
Index: src/TortoiseShell/PreserveChdir.h
===================================================================
--- src/TortoiseShell/PreserveChdir.h	(revision 19653)
+++ src/TortoiseShell/PreserveChdir.h	(working copy)
@@ -33,10 +33,14 @@
 class PreserveChdir
 {
 public:
-    PreserveChdir();
-    ~PreserveChdir();
+    PreserveChdir();                                ///< saves originalCurrentDirectory
+    ~PreserveChdir();                               ///< restores originalCurrentDirectory
 
 private:
-    auto_buffer<TCHAR> originalCurrentDirectory;
+    PreserveChdir(const PreserveChdir&);            ///< non-copyable
+    PreserveChdir& operator=(const PreserveChdir&); ///< non-assignable
+
+    const size_t size;                              ///< size of originalCurrentDirectory
+    auto_buffer<TCHAR> originalCurrentDirectory;    ///< %CD% at ctor time
 };
 
