Hi,
While trying to track down a bug in my own code, I had a memory tracer
showing use of freed memory here:

https://github.com/sandstorm-io/capnproto/blob/cbacb18063db4056a7a4e84b9ba43b9db4731de4/c%2B%2B/src/kj/async-io.c%2B%2B#L721

The corruption is on the kj::Strings in the params variable.  I eventually
figured it out it only happens when the client is destroyed.before the
address resolves.  I'm pretty sure it's a consequence of the move lambda
capture trick where a functor is created instead of an actual lambda - the
main thread destroys the functor holding the moved variables before
the getaddrinfo thread has a chance to use them.

If you want this fixed then I think the only way is to copy instead of
moving the strings.  However, it's only triggered in rare cases; and since
it only happens when everything is shutting down anyway I'm not sure how
serious it is.  Does anyone think the performance loss of the copy is worth
the memory correctness?

C++14 generalised captures should also solve this, but I think it'll be a
while before that's an acceptable minimum requirement.

Thanks,

Mark.

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to