Unverified Commit a7ed13fa authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #344 from knowledge4igor/fix_two_heap_usage_after_free

Fix two heap usage after free
parents da66820d 1f3d6c92
......@@ -187,7 +187,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;
......@@ -202,10 +203,10 @@ Transport::asyncWriteImpl(Fd fd)
if (wq.size() == 0) {
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;
......@@ -228,21 +229,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));
......@@ -250,7 +250,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