mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 06:26:02 -07:00
Fixed resource leaks
This commit is contained in:
parent
d4936a2c78
commit
48af26e332
1 changed files with 23 additions and 12 deletions
35
httplib.h
35
httplib.h
|
@ -2232,15 +2232,27 @@ read_and_close_socket_ssl(socket_t sock, size_t keep_alive_max_count,
|
|||
SSL *ssl = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(ctx_mutex);
|
||||
|
||||
ssl = SSL_new(ctx);
|
||||
if (!ssl) { return false; }
|
||||
}
|
||||
|
||||
if (!ssl) {
|
||||
close_socket(sock);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto bio = BIO_new_socket(sock, BIO_NOCLOSE);
|
||||
SSL_set_bio(ssl, bio, bio);
|
||||
|
||||
if (!setup(ssl)) { return false; }
|
||||
if (!setup(ssl)) {
|
||||
SSL_shutdown(ssl);
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(ctx_mutex);
|
||||
SSL_free(ssl);
|
||||
}
|
||||
|
||||
close_socket(sock);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = false;
|
||||
|
||||
|
@ -2264,17 +2276,16 @@ read_and_close_socket_ssl(socket_t sock, size_t keep_alive_max_count,
|
|||
auto dummy_connection_close = false;
|
||||
ret = callback(strm, true, dummy_connection_close);
|
||||
}
|
||||
|
||||
SSL_shutdown(ssl);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(ctx_mutex);
|
||||
SSL_free(ssl);
|
||||
}
|
||||
|
||||
close_socket(sock);
|
||||
}
|
||||
|
||||
SSL_shutdown(ssl);
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(ctx_mutex);
|
||||
SSL_free(ssl);
|
||||
}
|
||||
|
||||
close_socket(sock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue