Commit b28cde8b authored by knowledge4igor's avatar knowledge4igor

Fix two cases when heap usage takes place after free

parent 2f5f5193
......@@ -191,7 +191,8 @@ Transport::asyncWriteImpl(Fd fd)
// cleanup will have been handled by handlePeerDisconnection
if (it == std::end(toWrite)) { return; }
auto & wq = it->second;
while (wq.size() > 0) {
bool stop = false;
while (!stop && wq.size() > 0) {
auto & entry = wq.front();
int flags = entry.flags;
const BufferHolder &buffer = entry.buffer;
......@@ -207,9 +208,9 @@ Transport::asyncWriteImpl(Fd fd)
toWrite.erase(fd);
reactor()->modifyFd(key(), fd, NotifyOn::Read, Polling::Mode::Edge);
}
stop = true;
};
bool halt = false;
size_t totalWritten = buffer.offset();
for (;;) {
ssize_t bytesWritten = 0;
......@@ -232,21 +233,20 @@ Transport::asyncWriteImpl(Fd fd)
else {
cleanUp();
deferred.reject(Pistache::Error::system("Could not write data"));
halt = true;
}
break;
}
else {
totalWritten += bytesWritten;
if (totalWritten >= buffer.size()) {
cleanUp();
if (buffer.isFile()) {
// done with the file buffer, nothing else knows whether to
// close it with the way the code is written.
::close(buffer.fd());
}
cleanUp();
// Cast to match the type of defered template
// to avoid a BadType exception
deferred.resolve(static_cast<ssize_t>(totalWritten));
......@@ -254,7 +254,6 @@ Transport::asyncWriteImpl(Fd fd)
}
}
}
if (halt) break;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment