Skip to content

Commit 7ca8702

Browse files
authored
Fix memory leaks in core shutdown path (#13027)
* Fix NetAccept leak in stop_accept() — delete objects after stopping and clear naVec. * Fix acceptor objects leak — delete SSLNextProtocolAccept, ProtocolProbeSessionAccept, and plugin accepts in stop_HttpProxyServer(). * Fix AIOCallback leak for API-originated AIO ops — add from_api flag, delete callback in io_complete and on error path.
1 parent e16aa16 commit 7ca8702

5 files changed

Lines changed: 23 additions & 1 deletion

File tree

include/iocore/aio/AIO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct AIOCallback : public Continuation {
8383
int64_t aio_result = 0;
8484
AIO_Reqs *aio_req = nullptr;
8585
ink_hrtime sleep_time = 0;
86+
bool from_api = false;
8687
SLINK(AIOCallback, alink); /* for AIO_Reqs::aio_temp_list */
8788
#if TS_USE_LINUX_IO_URING
8889
iovec iov = {}; // this is to support older kernels that only support readv/writev

src/api/InkAPI.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7067,11 +7067,13 @@ TSAIORead(int fd, off_t offset, char *buf, size_t buffSize, TSCont contp)
70677067
pAIO->aiocb.aio_buf = buf;
70687068
pAIO->action = pCont;
70697069
pAIO->thread = pCont->mutex->thread_holding;
7070+
pAIO->from_api = true;
70707071

70717072
if (ink_aio_read(pAIO, 1) == 1) {
70727073
return TS_SUCCESS;
70737074
}
70747075

7076+
delete pAIO;
70757077
return TS_ERROR;
70767078
}
70777079

@@ -7106,11 +7108,13 @@ TSAIOWrite(int fd, off_t offset, char *buf, const size_t bufSize, TSCont contp)
71067108
pAIO->aiocb.aio_nbytes = bufSize;
71077109
pAIO->action = pCont;
71087110
pAIO->thread = pCont->mutex->thread_holding;
7111+
pAIO->from_api = true;
71097112

71107113
if (ink_aio_write(pAIO, 1) == 1) {
71117114
return TS_SUCCESS;
71127115
}
71137116

7117+
delete pAIO;
71147118
return TS_ERROR;
71157119
}
71167120

src/iocore/aio/AIO.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ AIOCallback::io_complete(int event, void *data)
9999
if (!action.cancelled && action.continuation) {
100100
action.continuation->handleEvent(AIO_EVENT_DONE, this);
101101
}
102+
if (from_api) {
103+
delete this;
104+
}
102105
return EVENT_DONE;
103106
}
104107

src/iocore/net/UnixNetProcessor.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ void
167167
UnixNetProcessor::stop_accept()
168168
{
169169
SCOPED_MUTEX_LOCK(lock, naVecMutex, this_ethread());
170-
for (auto &na : naVec) {
170+
for (auto *na : naVec) {
171171
na->stop_accept();
172+
delete na;
172173
}
174+
naVec.clear();
173175
}
174176

175177
Action *

src/proxy/http/HttpProxyServerMain.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,16 @@ stop_HttpProxyServer()
376376
{
377377
sslNetProcessor.stop_accept();
378378
netProcessor.stop_accept();
379+
380+
for (auto &acceptor : HttpProxyAcceptors) {
381+
delete acceptor._accept;
382+
acceptor._accept = nullptr;
383+
}
384+
HttpProxyAcceptors.clear();
385+
386+
delete plugin_http_accept;
387+
plugin_http_accept = nullptr;
388+
389+
delete plugin_http_transparent_accept;
390+
plugin_http_transparent_accept = nullptr;
379391
}

0 commit comments

Comments
 (0)