fix coverity issue

This commit is contained in:
Andre Puschmann 2018-02-01 15:44:42 +01:00
parent 32bc0e0ac2
commit 36a53b9cfc
2 changed files with 12 additions and 22 deletions

View File

@ -590,15 +590,15 @@ int main(int argc, char *argv[])
/******************* This is copied from srsue gw **********************/ /******************* This is copied from srsue gw **********************/
int setup_if_addr(char *ip_addr) int setup_if_addr(char *ip_addr)
{ {
char *dev = (char*) "tun_srsenb"; char *dev = (char*) "tun_srsenb";
int sock = 0;
// Construct the TUN device // Construct the TUN device
int tun_fd = open("/dev/net/tun", O_RDWR); int tun_fd = open("/dev/net/tun", O_RDWR);
if(0 > tun_fd) if(0 > tun_fd)
{ {
perror("open"); perror("open");
return(-1); return SRSLTE_ERROR;
} }
struct ifreq ifr; struct ifreq ifr;
@ -609,30 +609,23 @@ int setup_if_addr(char *ip_addr)
if(0 > ioctl(tun_fd, TUNSETIFF, &ifr)) if(0 > ioctl(tun_fd, TUNSETIFF, &ifr))
{ {
perror("ioctl1"); perror("ioctl1");
close(tun_fd); goto clean_exit;
return -1;
} }
// Bring up the interface // Bring up the interface
int sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
if(0 > ioctl(sock, SIOCGIFFLAGS, &ifr)) if(0 > ioctl(sock, SIOCGIFFLAGS, &ifr))
{ {
perror("socket"); perror("socket");
close(sock); goto clean_exit;
close(tun_fd);
return -1;
} }
ifr.ifr_flags |= IFF_UP | IFF_RUNNING; ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if(0 > ioctl(sock, SIOCSIFFLAGS, &ifr)) if(0 > ioctl(sock, SIOCSIFFLAGS, &ifr))
{ {
perror("ioctl2"); perror("ioctl2");
close(sock); goto clean_exit;
close(tun_fd);
return -1;
} }
close(sock);
// Setup the IP address // Setup the IP address
sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
ifr.ifr_addr.sa_family = AF_INET; ifr.ifr_addr.sa_family = AF_INET;
@ -640,21 +633,19 @@ int setup_if_addr(char *ip_addr)
if(0 > ioctl(sock, SIOCSIFADDR, &ifr)) if(0 > ioctl(sock, SIOCSIFADDR, &ifr))
{ {
perror("ioctl"); perror("ioctl");
close(sock); goto clean_exit;
close(tun_fd);
return -1;
} }
ifr.ifr_netmask.sa_family = AF_INET; ifr.ifr_netmask.sa_family = AF_INET;
((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0"); ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0");
if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr)) if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr))
{ {
perror("ioctl"); perror("ioctl");
close(sock); goto clean_exit;
close(tun_fd);
return -1;
} }
close(sock);
return(tun_fd); return(tun_fd);
clean_exit:
close(tun_fd);
return SRSLTE_ERROR;
} }

View File

@ -57,7 +57,6 @@ private:
std::string float_to_eng_string(float f, int digits); std::string float_to_eng_string(float f, int digits);
std::string int_to_eng_string(int f, int digits); std::string int_to_eng_string(int f, int digits);
float metrics_report_period;
bool do_print; bool do_print;
uint8_t n_reports; uint8_t n_reports;
ue_metrics_interface* ue; ue_metrics_interface* ue;