Skip to content

Commit e0cd175

Browse files
committed
Fix memory leak with SSL connections due to missing X509_free() calls.
Per Neil Conway.
1 parent 54840ec commit e0cd175

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/backend/libpq/be-secure.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.44 2003/11/29 19:51:49 pgsql Exp $
14+
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.45 2003/12/18 22:49:26 tgl Exp $
1515
*
1616
* Since the server static private key ($DataDir/server.key)
1717
* will normally be stored unencrypted so that the database
@@ -714,6 +714,9 @@ destroy_SSL(void)
714714
static int
715715
open_server_SSL(Port *port)
716716
{
717+
Assert(!port->ssl);
718+
Assert(!port->peer);
719+
717720
if (!(port->ssl = SSL_new(SSL_context)) ||
718721
!SSL_set_fd(port->ssl, port->sock) ||
719722
SSL_accept(port->ssl) <= 0)
@@ -764,6 +767,12 @@ close_SSL(Port *port)
764767
SSL_free(port->ssl);
765768
port->ssl = NULL;
766769
}
770+
771+
if (port->peer)
772+
{
773+
X509_free(port->peer);
774+
port->peer = NULL;
775+
}
767776
}
768777

769778
/*

src/interfaces/libpq/fe-secure.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.33 2003/11/29 19:52:12 pgsql Exp $
14+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.34 2003/12/18 22:49:26 tgl Exp $
1515
*
1616
* NOTES
1717
* The client *requires* a valid server certificate. Since
@@ -1004,6 +1004,12 @@ close_SSL(PGconn *conn)
10041004
SSL_free(conn->ssl);
10051005
conn->ssl = NULL;
10061006
}
1007+
1008+
if (conn->peer)
1009+
{
1010+
X509_free(conn->peer);
1011+
conn->peer = NULL;
1012+
}
10071013
}
10081014

10091015
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy