8217441: Failure of ::realloc() should be handled correctly in sawindbg.cpp

Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
Alex Menkov 2020-03-13 12:25:25 -07:00
parent c7e4b2afe2
commit 3aeb2d1a51

View File

@ -312,11 +312,13 @@ STDMETHODIMP SAOutputCallbacks::Output(THIS_
}
strcpy(m_msgBuffer, msg);
} else {
m_msgBuffer = (char*) realloc(m_msgBuffer, len + strlen(m_msgBuffer));
if (m_msgBuffer == 0) {
char* newBuffer = (char*)realloc(m_msgBuffer, len + strlen(m_msgBuffer));
if (newBuffer == nullptr) {
// old m_msgBuffer buffer is still valid
fprintf(stderr, "out of memory debugger output!\n");
return S_FALSE;
}
m_msgBuffer = newBuffer;
strcat(m_msgBuffer, msg);
}
return S_OK;