#6488 Fixed a memory leak in the TLS socket code

This commit is contained in:
Jnewbon 2019-04-29 13:56:08 +01:00 committed by GitHub
parent 9bccfb89cc
commit a56abf68dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -199,6 +199,7 @@ SecureSocket::doWrite()
{ {
static bool s_retry = false; static bool s_retry = false;
static int s_retrySize = 0; static int s_retrySize = 0;
static int s_staticBufferSize = 0;
static void* s_staticBuffer = NULL; static void* s_staticBuffer = NULL;
// write data // write data
@ -211,8 +212,13 @@ SecureSocket::doWrite()
} }
else { else {
bufferSize = m_outputBuffer.getSize(); bufferSize = m_outputBuffer.getSize();
s_staticBuffer = malloc(bufferSize); if (bufferSize != 0) {
memcpy(s_staticBuffer, m_outputBuffer.peek(bufferSize), bufferSize); if (bufferSize > s_staticBufferSize) {
s_staticBuffer = realloc(s_staticBuffer, bufferSize);
s_staticBufferSize = bufferSize;
}
memcpy(s_staticBuffer, m_outputBuffer.peek(bufferSize), bufferSize);
}
} }
if (bufferSize == 0) { if (bufferSize == 0) {
@ -224,8 +230,6 @@ SecureSocket::doWrite()
if (status > 0) { if (status > 0) {
s_retry = false; s_retry = false;
bufferSize = 0; bufferSize = 0;
free(s_staticBuffer);
s_staticBuffer = NULL;
} }
else if (status < 0) { else if (status < 0) {
return kBreak; return kBreak;