From: Matt Caswell Date: Fri, 12 Dec 2014 11:05:21 +0000 (+0000) Subject: Fix memory leak in s2_srvr.c if BUF_MEM_grow fails X-Git-Tag: OpenSSL_1_0_1k~53 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c983a77887519f4f82f4b0745a6d91f36344eedf;p=oweals%2Fopenssl.git Fix memory leak in s2_srvr.c if BUF_MEM_grow fails Reviewed-by: Tim Hudson Reviewed-by: Kurt Roeckx (cherry picked from commit d04a1e0b5beb3329cdf8c4ec35b9113cbc41d2f2) --- diff --git a/ssl/s2_srvr.c b/ssl/s2_srvr.c index 2cba426bb7..59ced3f305 100644 --- a/ssl/s2_srvr.c +++ b/ssl/s2_srvr.c @@ -188,13 +188,21 @@ int ssl2_accept(SSL *s) s->version=SSL2_VERSION; s->type=SSL_ST_ACCEPT; - buf=s->init_buf; - if ((buf == NULL) && ((buf=BUF_MEM_new()) == NULL)) - { ret= -1; goto end; } - if (!BUF_MEM_grow(buf,(int) - SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) - { ret= -1; goto end; } - s->init_buf=buf; + if(s->init_buf == NULL) + { + if ((buf=BUF_MEM_new()) == NULL) + { + ret= -1; + goto end; + } + if (!BUF_MEM_grow(buf,(int) SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) + { + BUF_MEM_free(buf); + ret= -1; + goto end; + } + s->init_buf=buf; + } s->init_num=0; s->ctx->stats.sess_accept++; s->handshake_func=ssl2_accept;