The client does not keep the RPC response object alive long enough.

The problem is in this line:

```
auto entries = test.getEntriesRequest().send().wait(waitScope).getEntries();
```

`entries` is a reference to the interior of the response, but the response
is a temporary object that goes away after the statement has been executed.
So `entries` points to invalid memory.

To fix the problem, you need to hold on to the response at least as long as
you deal with its interior. The easiest way to do that would be to split
out another assignment, like this:

```
auto response = test.getEntriesRequest().send().wait(waitScope);
auto entries = response.getEntries();
```

- David








On Mon, Feb 20, 2017 at 11:24 AM, Johannes Zeppenfeld <[email protected]>
wrote:

> Hi,
>
> I'm using Cap'n Proto version 0.5.3, and must be doing something
> fundamentally wrong with the RPC interface.
>
> I have a bootstrap interface containing a method that returns a list of
> entry information structures, which in turn contain a reference to a
> server-side entry object:
>
> interface Test {
>  getEntries @0 () -> (entries :List(Entry.Info));
> }
>
>
> interface Entry {
>  struct Info {
>  entry @0 :Entry;
>  name @1 :Text;
>  }
> }
>
>
>
> When attempting to iterate through the returned list in the client, a
> client-side exception is thrown:
>
> terminate called after throwing an instance of 'kj::ExceptionImpl'
>   what():  src/capnp/layout.c++:2105: failed: expected ref->kind() ==
> WirePointer::LIST; Message contains non-list pointer where text was
> expected.
>
>
> Everything works fine if the entry field is removed from Entry.Info.
>
> Any ideas as to what I am doing wrong? A full code example is attached.
>
> Thanks!
> Johannes
>
> --
> 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.
>

-- 
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