Fix Coverity Scan CID 340228 (Handle variable s going out of scope leaks the handle.)
This commit is contained in:
@@ -218,6 +218,7 @@ error:
|
|||||||
|
|
||||||
socket_link_t *new_link_udp_client(const char *server, int port){
|
socket_link_t *new_link_udp_client(const char *server, int port){
|
||||||
|
|
||||||
|
int s = -1;
|
||||||
socket_link_t *ret = NULL;
|
socket_link_t *ret = NULL;
|
||||||
ret = calloc(1, sizeof(socket_link_t));
|
ret = calloc(1, sizeof(socket_link_t));
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
@@ -227,7 +228,6 @@ socket_link_t *new_link_udp_client(const char *server, int port){
|
|||||||
ret->socket_fd = -1;
|
ret->socket_fd = -1;
|
||||||
|
|
||||||
struct sockaddr_in si_other;
|
struct sockaddr_in si_other;
|
||||||
int s;
|
|
||||||
socklen_t slen = sizeof(si_other);
|
socklen_t slen = sizeof(si_other);
|
||||||
|
|
||||||
if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
||||||
@@ -254,8 +254,12 @@ socket_link_t *new_link_udp_client(const char *server, int port){
|
|||||||
return ret;
|
return ret;
|
||||||
error:
|
error:
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
close(ret->socket_fd);
|
|
||||||
free(ret);
|
free(ret);
|
||||||
|
ret = NULL;
|
||||||
|
}
|
||||||
|
if (s != -1) {
|
||||||
|
close(s);
|
||||||
|
s = -1;
|
||||||
}
|
}
|
||||||
LOG_E(MAC, "ERROR in new_link_udp_client (see above), returning NULL\n");
|
LOG_E(MAC, "ERROR in new_link_udp_client (see above), returning NULL\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user