Skip to content

Commit

Permalink
Remove pointless null validations after new
Browse files Browse the repository at this point in the history
If new fails, it throws an exception.
  • Loading branch information
orgads committed Apr 1, 2024
1 parent ab788f5 commit fdda9de
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 49 deletions.
3 changes: 0 additions & 3 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
22 changes: 0 additions & 22 deletions src/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"
Expand Down Expand Up @@ -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) &&
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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. */
Expand Down
15 changes: 0 additions & 15 deletions src/stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions src/variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

Expand Down Expand Up @@ -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");
}
}
}

Expand All @@ -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;
Expand Down

0 comments on commit fdda9de

Please sign in to comment.