--- /dev/null
+
+ This patch is fixes Fix bug #1246 Sometimes access with 
+ VSS enabled. UCS conversion cache was not properly flushed 
+ at the end of a Job.
+
+ Apply it to version 2.4.4 with:
+
+ cd <bacula-source>
+ patch -p0 <2.4.4-winvss.patch
+ ./configure <your options>
+ make
+ ...
+ make install
+
+
+Index: src/filed/job.c
+===================================================================
+--- src/filed/job.c    (revision 8733)
++++ src/filed/job.c    (working copy)
+@@ -1,7 +1,7 @@
+ /*
+    Bacula® - The Network Backup Solution
+ 
+-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
++   Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+ 
+    The main author of Bacula is Kern Sibbald, with contributions from
+    many others, a complete list can be found in the file AUTHORS.
+@@ -41,7 +41,7 @@
+ #include "vss.h"
+ 
+ static pthread_mutex_t vss_mutex = PTHREAD_MUTEX_INITIALIZER;
+-static int enable_vss;
++static int enable_vss = 0;
+ #endif
+ 
+ extern CLIENT *me;                    /* our client resource */
+@@ -1422,7 +1422,7 @@
+                /* inform user about writer states */
+                for (i=0; i < (int)g_pVSSClient->GetWriterCount(); i++)                
+                   if (g_pVSSClient->GetWriterState(i) < 1) {
+-                     Jmsg(jcr, M_WARNING, 0, _("VSS Writer (PrepareForBackup): %s\n"), g_pVSSClient->GetWriterInfo(i));                    
++                     Jmsg(jcr, M_WARNING, 0, _("VSS Writer (PrepareForBackup): %s\n"), g_pVSSClient->GetWriterInfo(i));
+                      jcr->Errors++;
+                   }                            
+             }
+@@ -1506,6 +1506,7 @@
+             Jmsg(jcr, msg_type, 0, _("VSS Writer (BackupComplete): %s\n"), g_pVSSClient->GetWriterInfo(i));
+          }
+       }
++      Win32ConvCleanupCache();
+       V(vss_mutex);
+    }
+ #endif
+Index: src/win32/Makefile
+===================================================================
+--- src/win32/Makefile (revision 8733)
++++ src/win32/Makefile (working copy)
+@@ -30,7 +30,7 @@
+ Makefile.inc: Makefile.inc.in
+       @echo Creating $@
+       $(ECHO_CMD)TOPDIR=`(cd ../../..;pwd)`; \
+-      if test -e ../../../cross-tools/mingw32/bin/mingw32-gcc; then \
++      if test -e $${TOPDIR}/cross-tools/mingw32/bin/mingw32-gcc; then \
+               BINDIR=$${TOPDIR}/cross-tools/mingw32/bin; \
+               INCDIR=$${TOPDIR}/cross-tools/mingw32/mingw32/include; \
+               DLLDIR=$${TOPDIR}/cross-tools/mingw32/mingw32/bin; \
+@@ -43,7 +43,7 @@
+               echo "You must run build-win32-cross-tools and build-dependencies first.\n"; \
+               exit 1; \
+       fi ; \
+-      $(ECHO_CMD)BUILDDIR=`(pwd)`; \
++      BUILDDIR=`(pwd)`; \
+       sed \
+               -e "s^@BUILDDIR@^$${BUILDDIR}^" \
+               -e "s^@TOPDIR@^$${TOPDIR}^" \
+Index: src/win32/compat/compat.cpp
+===================================================================
+--- src/win32/compat/compat.cpp        (revision 8733)
++++ src/win32/compat/compat.cpp        (working copy)
+@@ -1,7 +1,7 @@
+ /*
+    Bacula® - The Network Backup Solution
+ 
+-   Copyright (C) 2004-2008 Free Software Foundation Europe e.V.
++   Copyright (C) 2004-2009 Free Software Foundation Europe e.V.
+ 
+    The main author of Bacula is Kern Sibbald, with contributions from
+    many others, a complete list can be found in the file AUTHORS.
+@@ -51,8 +51,8 @@
+    conversion is called 3 times (lstat, attribs, open),
+    by using the cache this is reduced to 1 time */
+ 
+-static POOLMEM *g_pWin32ConvUTF8Cache = get_pool_memory(PM_FNAME);
+-static POOLMEM *g_pWin32ConvUCS2Cache = get_pool_memory(PM_FNAME);
++static POOLMEM *g_pWin32ConvUTF8Cache = NULL;
++static POOLMEM *g_pWin32ConvUCS2Cache = NULL;
+ static DWORD g_dwWin32ConvUTF8strlen = 0;
+ static pthread_mutex_t Win32Convmutex = PTHREAD_MUTEX_INITIALIZER;
+ 
+@@ -69,8 +69,19 @@
+    g_pVSSPathConvertW = pPathConvertW;
+ }
+ 
++static void Win32ConvInitCache()
++{
++   if (g_pWin32ConvUTF8Cache) {
++      return;
++   }
++   g_pWin32ConvUTF8Cache = get_pool_memory(PM_FNAME);
++   g_pWin32ConvUCS2Cache = get_pool_memory(PM_FNAME);
++}
++
++
+ void Win32ConvCleanupCache()
+ {
++   P(Win32Convmutex);
+    if (g_pWin32ConvUTF8Cache) {
+       free_pool_memory(g_pWin32ConvUTF8Cache);
+       g_pWin32ConvUTF8Cache = NULL;
+@@ -82,6 +93,7 @@
+    }
+ 
+    g_dwWin32ConvUTF8strlen = 0;
++   V(Win32Convmutex);
+ }
+ 
+ 
+@@ -451,11 +463,14 @@
+    /* if we find the utf8 string in cache, we use the cached ucs2 version.
+       we compare the stringlength first (quick check) and then compare the content.            
+    */
+-   if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) {
++   if (!g_pWin32ConvUTF8Cache) {
++      Win32ConvInitCache();
++   } else if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) {
+       if (bstrcmp(pszUTF, g_pWin32ConvUTF8Cache)) {
++         /* Return cached value */
+          int32_t nBufSize = sizeof_pool_memory(g_pWin32ConvUCS2Cache);
+          *pszUCS = check_pool_memory_size(*pszUCS, nBufSize);      
+-         wcscpy((LPWSTR) *pszUCS, (LPWSTR) g_pWin32ConvUCS2Cache);
++         wcscpy((LPWSTR) *pszUCS, (LPWSTR)g_pWin32ConvUCS2Cache);
+          V(Win32Convmutex);
+          return nBufSize / sizeof (WCHAR);
+       }
+@@ -477,7 +492,7 @@
+    wcscpy((LPWSTR) g_pWin32ConvUCS2Cache, (LPWSTR) *pszUCS);
+    
+    g_dwWin32ConvUTF8strlen = strlen(pszUTF);
+-   g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+1);
++   g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+2);
+    bstrncpy(g_pWin32ConvUTF8Cache, pszUTF, g_dwWin32ConvUTF8strlen+1);
+    V(Win32Convmutex);
+ 
+Index: src/win32/Makefile.inc.in
+===================================================================
+--- src/win32/Makefile.inc.in  (revision 8733)
++++ src/win32/Makefile.inc.in  (working copy)
+@@ -11,9 +11,9 @@
+ 
+ BUILDDIR := @BUILDDIR@
+ TOPDIR := @TOPDIR@
+-DEPKGS := $(TOPDIR)/depkgs-mingw32
++DEPKGS := @TOPDIR@/depkgs-mingw32
+ 
+-DOCDIR := $(TOPDIR)/docs
++DOCDIR := @TOPDIR@/docs
+ BINDIR := ../release
+ LIBDIR := ../release
+ OBJDIR := .
 
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2004-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2004-2009 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    conversion is called 3 times (lstat, attribs, open),
    by using the cache this is reduced to 1 time */
 
-static POOLMEM *g_pWin32ConvUTF8Cache = get_pool_memory(PM_FNAME);
-static POOLMEM *g_pWin32ConvUCS2Cache = get_pool_memory(PM_FNAME);
+static POOLMEM *g_pWin32ConvUTF8Cache = NULL;
+static POOLMEM *g_pWin32ConvUCS2Cache = NULL;
 static DWORD g_dwWin32ConvUTF8strlen = 0;
 static pthread_mutex_t Win32Convmutex = PTHREAD_MUTEX_INITIALIZER;
 
    g_pVSSPathConvertW = pPathConvertW;
 }
 
+static void Win32ConvInitCache()
+{
+   if (g_pWin32ConvUTF8Cache) {
+      return;
+   }
+   g_pWin32ConvUTF8Cache = get_pool_memory(PM_FNAME);
+   g_pWin32ConvUCS2Cache = get_pool_memory(PM_FNAME);
+}
+
 void Win32ConvCleanupCache()
 {
+   P(Win32Convmutex);
    if (g_pWin32ConvUTF8Cache) {
       free_pool_memory(g_pWin32ConvUTF8Cache);
       g_pWin32ConvUTF8Cache = NULL;
    }
 
    g_dwWin32ConvUTF8strlen = 0;
+   V(Win32Convmutex);
 }
 
 
    /* if we find the utf8 string in cache, we use the cached ucs2 version.
       we compare the stringlength first (quick check) and then compare the content.            
    */
-   if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) {
+   if (!g_pWin32ConvUTF8Cache) {
+      Win32ConvInitCache();
+   } else if (g_dwWin32ConvUTF8strlen == strlen(pszUTF)) {
       if (bstrcmp(pszUTF, g_pWin32ConvUTF8Cache)) {
+         /* Return cached value */
          int32_t nBufSize = sizeof_pool_memory(g_pWin32ConvUCS2Cache);
          *pszUCS = check_pool_memory_size(*pszUCS, nBufSize);      
-         wcscpy((LPWSTR) *pszUCS, (LPWSTR) g_pWin32ConvUCS2Cache);
+         wcscpy((LPWSTR) *pszUCS, (LPWSTR)g_pWin32ConvUCS2Cache);
          V(Win32Convmutex);
          return nBufSize / sizeof (WCHAR);
       }
    wcscpy((LPWSTR) g_pWin32ConvUCS2Cache, (LPWSTR) *pszUCS);
    
    g_dwWin32ConvUTF8strlen = strlen(pszUTF);
-   g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+1);
+   g_pWin32ConvUTF8Cache = check_pool_memory_size(g_pWin32ConvUTF8Cache, g_dwWin32ConvUTF8strlen+2);
    bstrncpy(g_pWin32ConvUTF8Cache, pszUTF, g_dwWin32ConvUTF8strlen+1);
    V(Win32Convmutex);