Stop a possible memory leak.
authorRichard Levitte <levitte@openssl.org>
Sat, 21 Dec 2002 23:49:21 +0000 (23:49 +0000)
committerRichard Levitte <levitte@openssl.org>
Sat, 21 Dec 2002 23:49:21 +0000 (23:49 +0000)
(I wonder why s2_connect() handles the initial buffer allocation slightly
differently...)
PR: 416

ssl/s23_clnt.c
ssl/s2_clnt.c
ssl/s3_clnt.c

index ffaf3baff3eed8770064bb2ad9476f67f9b918c5..64ee4269ec1069828f7e7f03d29b7ed470956c54 100644 (file)
@@ -105,7 +105,7 @@ SSL_METHOD *SSLv23_client_method(void)
 
 int ssl23_connect(SSL *s)
        {
-       BUF_MEM *buf;
+       BUF_MEM *buf=NULL;
        unsigned long Time=time(NULL);
        void (*cb)(const SSL *ssl,int type,int val)=NULL;
        int ret= -1;
@@ -159,6 +159,7 @@ int ssl23_connect(SSL *s)
                                        goto end;
                                        }
                                s->init_buf=buf;
+                               buf=NULL;
                                }
 
                        if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
@@ -207,6 +208,8 @@ int ssl23_connect(SSL *s)
                }
 end:
        s->in_handshake--;
+       if (buf != NULL)
+               BUF_MEM_free(buf);
        if (cb != NULL)
                cb(s,SSL_CB_CONNECT_EXIT,ret);
        return(ret);
index da783230a521602326e8fba6cd1c4dd4d5f041fd..0bc04d284e83060164cc2a429ca23d686761c20b 100644 (file)
@@ -208,10 +208,13 @@ int ssl2_connect(SSL *s)
                        if (!BUF_MEM_grow(buf,
                                SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER))
                                {
+                               if (buf == s->init_buf)
+                                       buf=NULL;
                                ret= -1;
                                goto end;
                                }
                        s->init_buf=buf;
+                       buf=NULL;
                        s->init_num=0;
                        s->state=SSL2_ST_SEND_CLIENT_HELLO_A;
                        s->ctx->stats.sess_connect++;
@@ -338,6 +341,8 @@ int ssl2_connect(SSL *s)
                }
 end:
        s->in_handshake--;
+       if (buf != NULL)
+               BUF_MEM_free(buf);
        if (cb != NULL) 
                cb(s,SSL_CB_CONNECT_EXIT,ret);
        return(ret);
index aff0d9e61b079717715f0c5bcfc95d7329478fde..477b6816453c4c1395776741036a0ec57b465add 100644 (file)
@@ -183,7 +183,7 @@ SSL_METHOD *SSLv3_client_method(void)
 
 int ssl3_connect(SSL *s)
        {
-       BUF_MEM *buf;
+       BUF_MEM *buf=NULL;
        unsigned long Time=time(NULL),l;
        long num1;
        void (*cb)(const SSL *ssl,int type,int val)=NULL;
@@ -244,6 +244,7 @@ int ssl3_connect(SSL *s)
                                        goto end;
                                        }
                                s->init_buf=buf;
+                               buf=NULL;
                                }
 
                        if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
@@ -529,6 +530,8 @@ int ssl3_connect(SSL *s)
                }
 end:
        s->in_handshake--;
+       if (buf != NULL)
+               BUF_MEM_free(buf);
        if (cb != NULL)
                cb(s,SSL_CB_CONNECT_EXIT,ret);
        return(ret);