From 16c4673b1987116fe455c830daf044fb9c761e7b Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 12 Jul 2010 18:39:02 +0200 Subject: [PATCH] Cleanup dlists in VSSClient class at end of each job --- bacula/src/filed/job.c | 1 + bacula/src/win32/filed/vss.cpp | 50 ++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 769beb6267..cab2be070c 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -1907,6 +1907,7 @@ cleanup: #if defined(WIN32_VSS) if (jcr->VSS) { Win32ConvCleanupCache(); + g_pVSSClient->DestroyWriterInfo(); V(vss_mutex); } #endif diff --git a/bacula/src/win32/filed/vss.cpp b/bacula/src/win32/filed/vss.cpp index 6ab1baa6d1..376a8eb3f6 100644 --- a/bacula/src/win32/filed/vss.cpp +++ b/bacula/src/win32/filed/vss.cpp @@ -56,28 +56,34 @@ VSSCleanup() { if (g_pVSSClient) { delete (g_pVSSClient); + g_pVSSClient = NULL; } } +/* + * May be called multiple times + */ void VSSInit() { + if (g_pVSSClient) { + return; /* already initialized */ + } /* decide which vss class to initialize */ if (g_MajorVersion == 5) { switch (g_MinorVersion) { case 1: g_pVSSClient = new VSSClientXP(); - atexit(VSSCleanup); - return; + break; case 2: g_pVSSClient = new VSSClient2003(); - atexit(VSSCleanup); - return; + break; } /* Vista or Longhorn or later */ } else if (g_MajorVersion >= 6) { g_pVSSClient = new VSSClientVista(); + } + if (g_pVSSClient) { atexit(VSSCleanup); - return; } } @@ -206,21 +212,19 @@ bool VSSClient::GetShadowPathW(const wchar_t *szFilePath, wchar_t *szShadowPath, const size_t VSSClient::GetWriterCount() { - alist* pV = m_pAlistWriterInfoText; - return pV->size(); + return m_pAlistWriterInfoText->size(); } const char* VSSClient::GetWriterInfo(int nIndex) { - alist* pV = m_pAlistWriterInfoText; - return (char*)pV->get(nIndex); + return (char*)m_pAlistWriterInfoText->get(nIndex); } const int VSSClient::GetWriterState(int nIndex) { - alist* pV = m_pAlistWriterState; - void *item = pV->get(nIndex); + void *item = m_pAlistWriterState->get(nIndex); + /* Eliminate compiler warnings */ #ifdef HAVE_VSS64 return (int64_t)(char *)item; @@ -231,23 +235,23 @@ const int VSSClient::GetWriterState(int nIndex) void VSSClient::AppendWriterInfo(int nState, const char* pszInfo) { - alist* pT = m_pAlistWriterInfoText; - alist* pS = m_pAlistWriterState; - - pT->push(bstrdup(pszInfo)); - pS->push((void*)nState); + m_pAlistWriterInfoText->push(bstrdup(pszInfo)); + m_pAlistWriterState->push((void*)nState); } +/* + * Note, this is called at the end of every job, so release all + * the items in the alists, but do not delete the alist. + */ void VSSClient::DestroyWriterInfo() { - alist* pT = m_pAlistWriterInfoText; - alist* pS = m_pAlistWriterState; - - while (!pT->empty()) - free(pT->pop()); + while (!m_pAlistWriterInfoText->empty()) { + free(m_pAlistWriterInfoText->pop()); + } - while (!pS->empty()) - pS->pop(); + while (!m_pAlistWriterState->empty()) { + m_pAlistWriterState->pop(); + } } #endif -- 2.39.5