net: mqtt: Fix SOCKS5 setsockopt error handling

Transports should close the socket in case of `setsockopt()` failure,
otherwise we end up with a leaked socket, as it won't be closed
elsewhere.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2021-12-01 12:48:48 +01:00 committed by Maureen Helm
parent abbc89f026
commit 5110629ac1
2 changed files with 7 additions and 4 deletions

View file

@ -36,7 +36,7 @@ int mqtt_client_tcp_connect(struct mqtt_client *client)
&client->transport.proxy.addr,
client->transport.proxy.addrlen);
if (ret < 0) {
return -errno;
goto error;
}
}
#endif
@ -52,12 +52,15 @@ int mqtt_client_tcp_connect(struct mqtt_client *client)
ret = zsock_connect(client->transport.tcp.sock, client->broker,
peer_addr_size);
if (ret < 0) {
(void) zsock_close(client->transport.tcp.sock);
return -errno;
goto error;
}
MQTT_TRC("Connect completed");
return 0;
error:
(void)zsock_close(client->transport.tcp.sock);
return -errno;
}
int mqtt_client_tcp_write(struct mqtt_client *client, const uint8_t *data,

View file

@ -39,7 +39,7 @@ int mqtt_client_tls_connect(struct mqtt_client *client)
&client->transport.proxy.addr,
client->transport.proxy.addrlen);
if (ret < 0) {
return -errno;
goto error;
}
}
#endif