Hello,

there seems to be a small memory leak in b_sock.c.

In an application, I have used the following code fragment:

  if ((accept_bio = BIO_new_accept (bind_address)))
    {
    if (0 < BIO_set_bind_mode (accept_bio, BIO_BIND_REUSEADDR))
      if (0 < BIO_do_accept (accept_bio))
        return 1;

    BIO_free_all (accept_bio);
    }
  return 0;

When testing with bind_address = "foo.bar:1234" I got of course the
error "bad hostname lookup".  Additionally, I was shown a memory
leak:

     63 file=buffer.c, line=135, number=13, address=081B67B8
  13 bytes leaked in 1 chunks

With the debugger I tracked it down to the function
`BIO_get_accept_socket()' in `crypto/bio/b_sock.c':

    if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);

    [...]

    if (strcmp(h,"*") == 0)
        server.sin_addr.s_addr=INADDR_ANY;
    else
        {
        if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET);
    [...]

err:
    if (str != NULL) OPENSSL_free(str);
    if ((ret == 0) && (s != INVALID_SOCKET))
        {
        closesocket(s);
        s= INVALID_SOCKET;
        }
    return(s);
    }

First, the string `host' is pointing to is duplicated, but later,
when `BIO_get_host_ip()' fails, it isn't freed.  To correct this, I
have inserted a `goto err' where this string is freed:

--- b_sock.c-orig       Mon Sep 11 14:42:14 2000
+++ b_sock.c    Sun Feb 05 06:14:03 2001
@@ -553,7 +553,7 @@
                h="*";
                }
 
-       if (!BIO_get_port(p,&port)) return(INVALID_SOCKET);
+       if (!BIO_get_port(p,&port)) goto err;
 
        memset((char *)&server,0,sizeof(server));
        server.sin_family=AF_INET;
@@ -563,7 +563,7 @@
                server.sin_addr.s_addr=INADDR_ANY;
        else
                {
-               if (!BIO_get_host_ip(h,&(ip[0])))
+               if (!BIO_get_host_ip(h,&(ip[0]))) goto err;
return(INVALID_SOCKET);
                l=(unsigned long)
                        ((unsigned long)ip[0]<<24L)|
                        ((unsigned long)ip[1]<<16L)|


Best regargs,
Niko




______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to