Skip to content

Commit b64e221

Browse files
committed
Merge branch 'PHP-5.5'
* PHP-5.5: - Bug #65228 (FTPs memory leak) patch by: marco dot beierer at mbsecurity dot ch
2 parents b98f346 + efc8936 commit b64e221

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ext/ftp/ftp.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ ftp_close(ftpbuf_t *ftp)
182182
#if HAVE_OPENSSL_EXT
183183
if (ftp->ssl_active) {
184184
SSL_shutdown(ftp->ssl_handle);
185+
SSL_free(ftp->ssl_handle);
185186
}
186187
#endif
187188
closesocket(ftp->fd);
@@ -297,6 +298,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass TSRMLS_DC)
297298
if (SSL_connect(ftp->ssl_handle) <= 0) {
298299
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed");
299300
SSL_shutdown(ftp->ssl_handle);
301+
SSL_free(ftp->ssl_handle);
300302
return 0;
301303
}
302304

@@ -1548,6 +1550,7 @@ data_accept(databuf_t *data, ftpbuf_t *ftp TSRMLS_DC)
15481550
if (SSL_connect(data->ssl_handle) <= 0) {
15491551
php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: SSL/TLS handshake failed");
15501552
SSL_shutdown(data->ssl_handle);
1553+
SSL_free(data->ssl_handle);
15511554
return 0;
15521555
}
15531556

@@ -1565,13 +1568,21 @@ data_accept(databuf_t *data, ftpbuf_t *ftp TSRMLS_DC)
15651568
databuf_t*
15661569
data_close(ftpbuf_t *ftp, databuf_t *data)
15671570
{
1571+
#if HAVE_OPENSSL_EXT
1572+
SSL_CTX *ctx;
1573+
#endif
15681574
if (data == NULL) {
15691575
return NULL;
15701576
}
15711577
if (data->listener != -1) {
15721578
#if HAVE_OPENSSL_EXT
15731579
if (data->ssl_active) {
1580+
1581+
ctx = SSL_get_SSL_CTX(data->ssl_handle);
1582+
SSL_CTX_free(ctx);
1583+
15741584
SSL_shutdown(data->ssl_handle);
1585+
SSL_free(data->ssl_handle);
15751586
data->ssl_active = 0;
15761587
}
15771588
#endif
@@ -1580,7 +1591,11 @@ data_close(ftpbuf_t *ftp, databuf_t *data)
15801591
if (data->fd != -1) {
15811592
#if HAVE_OPENSSL_EXT
15821593
if (data->ssl_active) {
1594+
ctx = SSL_get_SSL_CTX(data->ssl_handle);
1595+
SSL_CTX_free(ctx);
1596+
15831597
SSL_shutdown(data->ssl_handle);
1598+
SSL_free(data->ssl_handle);
15841599
data->ssl_active = 0;
15851600
}
15861601
#endif

0 commit comments

Comments
 (0)