From 36a53b9cfc29e89120e80c102a222c8c99e4576f Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Thu, 1 Feb 2018 15:44:42 +0100 Subject: [PATCH] fix coverity issue --- srsenb/test/upper/ip_test.cc | 33 ++++++++++++--------------------- srsue/hdr/metrics_stdout.h | 1 - 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/srsenb/test/upper/ip_test.cc b/srsenb/test/upper/ip_test.cc index 1d8423b9d..deceb486e 100644 --- a/srsenb/test/upper/ip_test.cc +++ b/srsenb/test/upper/ip_test.cc @@ -590,15 +590,15 @@ int main(int argc, char *argv[]) /******************* This is copied from srsue gw **********************/ int setup_if_addr(char *ip_addr) { - char *dev = (char*) "tun_srsenb"; + int sock = 0; // Construct the TUN device int tun_fd = open("/dev/net/tun", O_RDWR); if(0 > tun_fd) { perror("open"); - return(-1); + return SRSLTE_ERROR; } struct ifreq ifr; @@ -609,30 +609,23 @@ int setup_if_addr(char *ip_addr) if(0 > ioctl(tun_fd, TUNSETIFF, &ifr)) { perror("ioctl1"); - close(tun_fd); - return -1; + goto clean_exit; } // 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)) { perror("socket"); - close(sock); - close(tun_fd); - return -1; + goto clean_exit; } ifr.ifr_flags |= IFF_UP | IFF_RUNNING; if(0 > ioctl(sock, SIOCSIFFLAGS, &ifr)) { perror("ioctl2"); - close(sock); - close(tun_fd); - return -1; + goto clean_exit; } - close(sock); - // Setup the IP address sock = socket(AF_INET, SOCK_DGRAM, 0); ifr.ifr_addr.sa_family = AF_INET; @@ -640,21 +633,19 @@ int setup_if_addr(char *ip_addr) if(0 > ioctl(sock, SIOCSIFADDR, &ifr)) { perror("ioctl"); - close(sock); - close(tun_fd); - return -1; + goto clean_exit; } ifr.ifr_netmask.sa_family = AF_INET; ((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0"); if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr)) { perror("ioctl"); - close(sock); - close(tun_fd); - return -1; + goto clean_exit; } - - close(sock); return(tun_fd); + +clean_exit: + close(tun_fd); + return SRSLTE_ERROR; } diff --git a/srsue/hdr/metrics_stdout.h b/srsue/hdr/metrics_stdout.h index cd19e7f16..01f28f35e 100644 --- a/srsue/hdr/metrics_stdout.h +++ b/srsue/hdr/metrics_stdout.h @@ -57,7 +57,6 @@ private: std::string float_to_eng_string(float f, int digits); std::string int_to_eng_string(int f, int digits); - float metrics_report_period; bool do_print; uint8_t n_reports; ue_metrics_interface* ue;