mirror of
https://github.com/capnproto/pycapnp.git
synced 2025-03-04 08:24:43 +01:00
Avoid reading random values for reader options from dangling reference (#300)
This patch fixes a problem of reading random values for reader options in pycapnp. The code which adds task to the list captures 'opts' by reference and that causes a problem in case when 'opts' is allocated on on the caller's stack. By the time when task is handled the stack frame holding the 'opts' is gone which leaves dangling reference to 'opts' in lambda's captures. As a result pycapnp reads random values for reader options which sometimes causes unexpected errors (for example an error that nesting level ius negative).
This commit is contained in:
parent
1814105967
commit
e614da1025
1 changed files with 2 additions and 2 deletions
|
@ -40,7 +40,7 @@ struct ServerContext {
|
|||
void acceptLoop(kj::TaskSet & tasks, capnp::Capability::Client client, kj::Own<kj::ConnectionReceiver>&& listener, capnp::ReaderOptions & opts) {
|
||||
auto ptr = listener.get();
|
||||
tasks.add(ptr->accept().then(kj::mvCapture(kj::mv(listener),
|
||||
[&, client](kj::Own<kj::ConnectionReceiver>&& listener,
|
||||
[&, client, opts](kj::Own<kj::ConnectionReceiver>&& listener,
|
||||
kj::Own<kj::AsyncIoStream>&& connection) mutable {
|
||||
acceptLoop(tasks, client, kj::mv(listener), opts);
|
||||
|
||||
|
@ -58,7 +58,7 @@ kj::Promise<PyObject *> connectServer(kj::TaskSet & tasks, capnp::Capability::Cl
|
|||
|
||||
tasks.add(context->provider->getNetwork().parseAddress(bindAddress)
|
||||
.then(kj::mvCapture(paf.fulfiller,
|
||||
[&, client](kj::Own<kj::PromiseFulfiller<unsigned int>>&& portFulfiller,
|
||||
[&, client, opts](kj::Own<kj::PromiseFulfiller<unsigned int>>&& portFulfiller,
|
||||
kj::Own<kj::NetworkAddress>&& addr) mutable {
|
||||
auto listener = addr->listen();
|
||||
portFulfiller->fulfill(listener->getPort());
|
||||
|
|
Loading…
Add table
Reference in a new issue