Unverified Commit 949aa27f authored by Anx2k's avatar Anx2k Committed by GitHub

Update ssl_client.cpp (#6942)

Fixed issue with ssl_client->socket being closed without being consistently set to -1.  Changed close to lwip_close to be consistent with lwip_socket, resolved issue with long term assert after 4+ days (assert failed: lock_release_generic locks.c:186).
Co-authored-by: default avatarMe No Dev <me-no-dev@users.noreply.github.com>
parent 666c66d3
...@@ -100,18 +100,21 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p ...@@ -100,18 +100,21 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
int res = lwip_connect(ssl_client->socket, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); int res = lwip_connect(ssl_client->socket, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
if (res < 0 && errno != EINPROGRESS) { if (res < 0 && errno != EINPROGRESS) {
log_e("connect on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); log_e("connect on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno));
close(ssl_client->socket); lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1; return -1;
} }
res = select(ssl_client->socket + 1, nullptr, &fdset, nullptr, timeout<0 ? nullptr : &tv); res = select(ssl_client->socket + 1, nullptr, &fdset, nullptr, timeout<0 ? nullptr : &tv);
if (res < 0) { if (res < 0) {
log_e("select on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); log_e("select on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno));
close(ssl_client->socket); lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1; return -1;
} else if (res == 0) { } else if (res == 0) {
log_i("select returned due to timeout %d ms for fd %d", timeout, ssl_client->socket); log_i("select returned due to timeout %d ms for fd %d", timeout, ssl_client->socket);
close(ssl_client->socket); lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1; return -1;
} else { } else {
int sockerr; int sockerr;
...@@ -120,13 +123,15 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p ...@@ -120,13 +123,15 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
if (res < 0) { if (res < 0) {
log_e("getsockopt on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno)); log_e("getsockopt on fd %d, errno: %d, \"%s\"", ssl_client->socket, errno, strerror(errno));
close(ssl_client->socket); lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1; return -1;
} }
if (sockerr != 0) { if (sockerr != 0) {
log_e("socket error on fd %d, errno: %d, \"%s\"", ssl_client->socket, sockerr, strerror(sockerr)); log_e("socket error on fd %d, errno: %d, \"%s\"", ssl_client->socket, sockerr, strerror(sockerr));
close(ssl_client->socket); lwip_close(ssl_client->socket);
ssl_client->socket = -1;
return -1; return -1;
} }
} }
...@@ -319,7 +324,7 @@ void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, cons ...@@ -319,7 +324,7 @@ void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, cons
log_v("Cleaning SSL connection."); log_v("Cleaning SSL connection.");
if (ssl_client->socket >= 0) { if (ssl_client->socket >= 0) {
close(ssl_client->socket); lwip_close(ssl_client->socket);
ssl_client->socket = -1; ssl_client->socket = -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment