提交 8d6ad9e3 编写于 作者: R Richard Levitte

Stop a possible memory leak.

(I wonder why s2_connect() handles the initial buffer allocation slightly
differently...)
PR: 416
上级 aa18245f
...@@ -105,7 +105,7 @@ SSL_METHOD *SSLv23_client_method(void) ...@@ -105,7 +105,7 @@ SSL_METHOD *SSLv23_client_method(void)
int ssl23_connect(SSL *s) int ssl23_connect(SSL *s)
{ {
BUF_MEM *buf; BUF_MEM *buf=NULL;
unsigned long Time=time(NULL); unsigned long Time=time(NULL);
void (*cb)(const SSL *ssl,int type,int val)=NULL; void (*cb)(const SSL *ssl,int type,int val)=NULL;
int ret= -1; int ret= -1;
...@@ -159,6 +159,7 @@ int ssl23_connect(SSL *s) ...@@ -159,6 +159,7 @@ int ssl23_connect(SSL *s)
goto end; goto end;
} }
s->init_buf=buf; s->init_buf=buf;
buf=NULL;
} }
if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
...@@ -207,6 +208,8 @@ int ssl23_connect(SSL *s) ...@@ -207,6 +208,8 @@ int ssl23_connect(SSL *s)
} }
end: end:
s->in_handshake--; s->in_handshake--;
if (buf != NULL)
BUF_MEM_free(buf);
if (cb != NULL) if (cb != NULL)
cb(s,SSL_CB_CONNECT_EXIT,ret); cb(s,SSL_CB_CONNECT_EXIT,ret);
return(ret); return(ret);
......
...@@ -208,10 +208,13 @@ int ssl2_connect(SSL *s) ...@@ -208,10 +208,13 @@ int ssl2_connect(SSL *s)
if (!BUF_MEM_grow(buf, if (!BUF_MEM_grow(buf,
SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
{ {
if (buf == s->init_buf)
buf=NULL;
ret= -1; ret= -1;
goto end; goto end;
} }
s->init_buf=buf; s->init_buf=buf;
buf=NULL;
s->init_num=0; s->init_num=0;
s->state=SSL2_ST_SEND_CLIENT_HELLO_A; s->state=SSL2_ST_SEND_CLIENT_HELLO_A;
s->ctx->stats.sess_connect++; s->ctx->stats.sess_connect++;
...@@ -338,6 +341,8 @@ int ssl2_connect(SSL *s) ...@@ -338,6 +341,8 @@ int ssl2_connect(SSL *s)
} }
end: end:
s->in_handshake--; s->in_handshake--;
if (buf != NULL)
BUF_MEM_free(buf);
if (cb != NULL) if (cb != NULL)
cb(s,SSL_CB_CONNECT_EXIT,ret); cb(s,SSL_CB_CONNECT_EXIT,ret);
return(ret); return(ret);
......
...@@ -183,7 +183,7 @@ SSL_METHOD *SSLv3_client_method(void) ...@@ -183,7 +183,7 @@ SSL_METHOD *SSLv3_client_method(void)
int ssl3_connect(SSL *s) int ssl3_connect(SSL *s)
{ {
BUF_MEM *buf; BUF_MEM *buf=NULL;
unsigned long Time=time(NULL),l; unsigned long Time=time(NULL),l;
long num1; long num1;
void (*cb)(const SSL *ssl,int type,int val)=NULL; void (*cb)(const SSL *ssl,int type,int val)=NULL;
...@@ -244,6 +244,7 @@ int ssl3_connect(SSL *s) ...@@ -244,6 +244,7 @@ int ssl3_connect(SSL *s)
goto end; goto end;
} }
s->init_buf=buf; s->init_buf=buf;
buf=NULL;
} }
if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
...@@ -529,6 +530,8 @@ int ssl3_connect(SSL *s) ...@@ -529,6 +530,8 @@ int ssl3_connect(SSL *s)
} }
end: end:
s->in_handshake--; s->in_handshake--;
if (buf != NULL)
BUF_MEM_free(buf);
if (cb != NULL) if (cb != NULL)
cb(s,SSL_CB_CONNECT_EXIT,ret); cb(s,SSL_CB_CONNECT_EXIT,ret);
return(ret); return(ret);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册