Skip to content

Commit

Permalink
Add exception handling for m_table array allocation. - Moret84
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshasa committed Jan 20, 2025
1 parent d2327ac commit 53f6b28
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/torrent/poll_epoll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,21 @@ PollEPoll::create(int maxOpenSockets) {
return new PollEPoll(fd, 1024, maxOpenSockets);
}

PollEPoll::PollEPoll(int fd, int maxEvents, int maxOpenSockets) :
PollEPoll::PollEPoll(int fd, int max_events, int max_open_sockets) :
m_fd(fd),
m_maxEvents(maxEvents),
m_maxEvents(max_events),
m_waitingEvents(0),
m_events(new epoll_event[m_maxEvents]) {

m_table.resize(maxOpenSockets);
try {
m_table.resize(max_open_sockets);
} catch (std::bad_alloc) {
char errmsg[1024];
snprintf(errmsg, sizeof(errmsg),
"PollEPoll::PollEPoll(...): Error allocating m_table array: too much space requested: max_open_sockets:%d", max_open_sockets);

throw internal_error(errmsg);
}
}

PollEPoll::~PollEPoll() {
Expand Down

0 comments on commit 53f6b28

Please sign in to comment.