From fdda9de5d8ed5bca8757205d90a47ecf18995143 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 1 Apr 2024 19:35:55 +0300 Subject: [PATCH] Remove pointless null validations after new If new fails, it throws an exception. --- src/actions.cpp | 3 --- src/socket.cpp | 22 ---------------------- src/stat.cpp | 15 --------------- src/variables.cpp | 9 --------- 4 files changed, 49 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 34255ce5..6485030b 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -1043,9 +1043,6 @@ int CActions::getActionSize() void CActions::setAction(CAction *P_action) { CAction **newActions = new CAction*[M_nbAction + 1]; - if (!newActions) { - ERROR("Could not allocate new action list."); - } for (int i = 0; i < M_nbAction; i++) { newActions[i] = M_actionList[i]; } diff --git a/src/socket.cpp b/src/socket.cpp index f5dff4e3..6d865e35 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -534,9 +534,6 @@ void setup_ctrl_socket() } ctrl_socket = new SIPpSocket(0, T_UDP, sock, 0); - if (!ctrl_socket) { - ERROR_NO("Could not setup control socket!"); - } } void reset_stdin() @@ -552,9 +549,6 @@ void setup_stdin_socket() fcntl(stdin_fileno, F_SETFL, stdin_mode | O_NONBLOCK); stdin_socket = new SIPpSocket(0, T_TCP, stdin_fileno, 0); - if (!stdin_socket) { - ERROR_NO("Could not setup keyboard (stdin) socket!"); - } } #define SIPP_ENDL "\r\n" @@ -1131,9 +1125,6 @@ void process_message(SIPpSocket *socket, char *msg, ssize_t msg_size, struct soc // Adding a new OUTGOING call ! main_scenario->stats->computeStat(CStat::E_CREATE_OUTGOING_CALL); call *new_ptr = new call(call_id, local_ip_is_ipv6, 0, use_remote_sending_addr ? &remote_sending_sockaddr : &remote_sockaddr); - if (!new_ptr) { - ERROR("Out of memory allocating a call!"); - } outbound_congestion = false; if ((socket != main_socket) && @@ -1171,9 +1162,6 @@ void process_message(SIPpSocket *socket, char *msg, ssize_t msg_size, struct soc // Adding a new INCOMING call ! main_scenario->stats->computeStat(CStat::E_CREATE_INCOMING_CALL); listener_ptr = new call(call_id, socket, use_remote_sending_addr ? &remote_sending_sockaddr : src); - if (!listener_ptr) { - ERROR("Out of memory allocating a call!"); - } } else { // mode != from SERVER and 3PCC Controller B // This is a message that is not relating to any known call if (ooc_scenario) { @@ -1189,9 +1177,6 @@ void process_message(SIPpSocket *socket, char *msg, ssize_t msg_size, struct soc free(msg_start); /* This should have the real address that the message came from. */ call *call_ptr = new call(ooc_scenario, socket, use_remote_sending_addr ? &remote_sending_sockaddr : src, call_id, 0 /* no user. */, socket->ss_ipv6, true, false); - if (!call_ptr) { - ERROR("Out of memory allocating a call!"); - } CStat::globalStat(CStat::E_AUTO_ANSWERED); call_ptr->process_incoming(msg, src); } else { @@ -1211,9 +1196,6 @@ void process_message(SIPpSocket *socket, char *msg, ssize_t msg_size, struct soc aa_scenario->stats->computeStat(CStat::E_CREATE_INCOMING_CALL); /* This should have the real address that the message came from. */ call *call_ptr = new call(aa_scenario, socket, use_remote_sending_addr ? &remote_sending_sockaddr : src, call_id, 0 /* no user. */, socket->ss_ipv6, true, false); - if (!call_ptr) { - ERROR("Out of memory allocating a call!"); - } CStat::globalStat(CStat::E_AUTO_ANSWERED); call_ptr->process_incoming(msg, src); } else { @@ -1420,10 +1402,6 @@ SIPpSocket* SIPpSocket::accept() { #endif ret = new SIPpSocket(ss_ipv6, ss_transport, fd, 1); - if (!ret) { - ::close(fd); - ERROR_NO("Could not allocate new socket!"); - } /* We should connect back to the address which connected to us if we * experience a TCP failure. */ diff --git a/src/stat.cpp b/src/stat.cpp index 95150acf..f1f47251 100644 --- a/src/stat.cpp +++ b/src/stat.cpp @@ -370,11 +370,6 @@ void CStat::initRtt(const char* P_name, const char* P_extension, M_dumpRespTime = new T_value_rtt [P_report_freq_dumpRtt] ; - if ( M_dumpRespTime == nullptr ) { - std::cerr << "Memory allocation failure" << std::endl; - exit(EXIT_FATAL_ERROR); - } - for (unsigned L_i = 0 ; L_i < P_report_freq_dumpRtt; L_i ++) { M_dumpRespTime[L_i].date = 0.0; M_dumpRespTime[L_i].rtd_no = 0; @@ -1148,11 +1143,6 @@ void CStat::dumpData () M_outputStream = new std::ofstream(M_fileName); M_headerAlreadyDisplayed = false; - if(M_outputStream == nullptr) { - std::cerr << "Unable to open stat file '" << M_fileName << "' !" << std::endl; - exit(EXIT_FATAL_ERROR); - } - #ifndef __osf__ if(!M_outputStream->is_open()) { std::cerr << "Unable to open stat file '" << M_fileName << "' !" << std::endl; @@ -1396,11 +1386,6 @@ void CStat::dumpDataRtt () M_outputStreamRtt = new std::ofstream(M_fileNameRtt); M_headerAlreadyDisplayedRtt = false; - if(M_outputStreamRtt == nullptr) { - std::cerr << "Unable to open rtt file '" << M_fileNameRtt << "' !" << std::endl; - exit(EXIT_FATAL_ERROR); - } - #ifndef __osf__ if(!M_outputStreamRtt->is_open()) { std::cerr << "Unable to open rtt file '" << M_fileNameRtt << "' !" << std::endl; diff --git a/src/variables.cpp b/src/variables.cpp index 515d030d..aaea6c0b 100644 --- a/src/variables.cpp +++ b/src/variables.cpp @@ -207,9 +207,6 @@ VariableTable::VariableTable(VariableTable *parent, int size) } for (int i = 0; i < size; i++) { variableTable[i] = new CCallVariable(); - if (variableTable[i] == nullptr) { - ERROR ("Call variable allocation failed"); - } } } @@ -238,9 +235,6 @@ VariableTable::VariableTable(AllocVariableTable *src) for (int i = 0; i < size; i++) { variableTable[i] = new CCallVariable(); - if (variableTable[i] == nullptr) { - ERROR ("Call variable allocation failed"); - } } } @@ -258,9 +252,6 @@ void VariableTable::expand(int size) for (int i = this->size; i < size; i++) { variableTable[i] = new CCallVariable(); - if (variableTable[i] == nullptr) { - ERROR ("Call variable allocation failed"); - } } this->size = size;