diff options
author | ace20022 <ace20022@ymail.com> | 2013-09-26 11:28:01 +0200 |
---|---|---|
committer | ace20022 <ace20022@ymail.com> | 2013-09-26 11:33:20 +0200 |
commit | 3964f0d0f6e2f4b4f42d5e81ce07a6d89ed340f1 (patch) | |
tree | a90bf5de7ef6e1022217d8c4ec96d2cb2f24d191 /lib | |
parent | 75ad4ab37ab7474eec061385b62ae6de338add70 (diff) |
[cximage] Fix common realloc mistake: 'm_pBuffer' nulled but not freed upon failure in xmemfile.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cximage-6.0/CxImage/xmemfile.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/cximage-6.0/CxImage/xmemfile.cpp b/lib/cximage-6.0/CxImage/xmemfile.cpp index af8db945a3..5a72200238 100644 --- a/lib/cximage-6.0/CxImage/xmemfile.cpp +++ b/lib/cximage-6.0/CxImage/xmemfile.cpp @@ -186,9 +186,21 @@ bool CxMemFile::Alloc(DWORD dwNewLen) // allocate new buffer if (m_pBuffer == NULL) m_pBuffer = (BYTE*)malloc(dwNewBufferSize); - else m_pBuffer = (BYTE*)realloc(m_pBuffer, dwNewBufferSize); + else + { + BYTE* new_buf = (BYTE*)realloc(m_pBuffer, dwNewBufferSize); + if (!new_buf) + { + free(m_pBuffer); + m_bFreeOnClose = false; + return false; + } + else + m_pBuffer = new_buf; + } // I own this buffer now (caller knows nothing about it) - m_bFreeOnClose = true; + if (m_pBuffer) + m_bFreeOnClose = true; m_Edge = dwNewBufferSize; } |