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