From 5da2a551ce6f6a0f8ad47ad5e65f053ccc0b2b6f Mon Sep 17 00:00:00 2001 From: djp952 Date: Sun, 30 Jun 2019 00:01:32 -0400 Subject: [PATCH] Corrections to CircularCache initialization and termination --- xbmc/filesystem/CircularCache.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xbmc/filesystem/CircularCache.cpp b/xbmc/filesystem/CircularCache.cpp index 5709a67d536c9..41561c7351abc 100644 --- a/xbmc/filesystem/CircularCache.cpp +++ b/xbmc/filesystem/CircularCache.cpp @@ -24,7 +24,7 @@ CCircularCache::CCircularCache(size_t front, size_t back) , m_size(front + back) , m_size_back(back) #ifdef TARGET_WINDOWS - , m_handle(INVALID_HANDLE_VALUE) + , m_handle(NULL) #endif { } @@ -44,7 +44,7 @@ int CCircularCache::Open() #else m_buf = new uint8_t[m_size]; #endif - if(m_buf == 0) + if (m_buf == NULL) return CACHE_RC_ERROR; m_beg = 0; m_end = 0; @@ -55,9 +55,11 @@ int CCircularCache::Open() void CCircularCache::Close() { #ifdef TARGET_WINDOWS - UnmapViewOfFile(m_buf); - CloseHandle(m_handle); - m_handle = INVALID_HANDLE_VALUE; + if (m_buf != NULL) + UnmapViewOfFile(m_buf); + if (m_handle != NULL) + CloseHandle(m_handle); + m_handle = NULL; #else delete[] m_buf; #endif @@ -118,6 +120,9 @@ int CCircularCache::WriteToCache(const char *buf, size_t len) if(len == 0) return 0; + if (m_buf == NULL) + return 0; + // write the data memcpy(m_buf + pos, buf, len); m_end += len; @@ -158,6 +163,9 @@ int CCircularCache::ReadFromCache(char *buf, size_t len) if(len == 0) return 0; + if (m_buf == NULL) + return 0; + memcpy(buf, m_buf + pos, len); m_cur += len;