Fix memory leak with SSL connections due to missing X509_free() calls.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 18 Dec 2003 22:49:34 +0000 (22:49 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 18 Dec 2003 22:49:34 +0000 (22:49 +0000)
Per Neil Conway.

src/backend/libpq/be-secure.c
src/interfaces/libpq/fe-secure.c

index f85574714c783b819ae5feb87b1b72a1fde8a8b2..24c8e34dd9703a1246ef3014464de0a40a27c17e 100644 (file)
@@ -714,6 +714,9 @@ destroy_SSL(void)
 static int
 open_server_SSL(Port *port)
 {
+       Assert(!port->ssl);
+       Assert(!port->peer);
+
        if (!(port->ssl = SSL_new(SSL_context)) ||
                !SSL_set_fd(port->ssl, port->sock) ||
                SSL_accept(port->ssl) <= 0)
@@ -764,6 +767,12 @@ close_SSL(Port *port)
                SSL_free(port->ssl);
                port->ssl = NULL;
        }
+
+       if (port->peer)
+       {
+               X509_free(port->peer);
+               port->peer = NULL;
+       }
 }
 
 /*
index 35a38ba4c00b3f33af1dfc712cbb731164b4ddf9..9fb2140d9bb3769a94a39083ff5744d0bb20b6a0 100644 (file)
@@ -1004,6 +1004,12 @@ close_SSL(PGconn *conn)
                SSL_free(conn->ssl);
                conn->ssl = NULL;
        }
+
+       if (conn->peer)
+       {
+               X509_free(conn->peer);
+               conn->peer = NULL;
+       }
 }
 
 /*