-
Notifications
You must be signed in to change notification settings - Fork 909
Closed
Description
From what I can tell by the comments in unpack.hpp, unpacker objects are meant to live for the lifetime of the input source. However, using it to implement MessagePack-RPC, it leaks memory.
Consider this example:
#include <msgpack.hpp>
int main(int argc, char **argv)
{
// Build a buffer containing a sample msgpack-rpc message
msgpack::sbuffer sbuf;
msgpack::packer<msgpack::sbuffer> packer(&sbuf);
packer.pack_array(4);
packer.pack(0);
packer.pack(123456);
packer.pack(std::string("method"));
packer.pack_array(2);
packer.pack(std::string("strarg"));
packer.pack(42);
// Simulate receiving the message from the network
msgpack::unpacker pac;
while (1) {
pac.reserve_buffer(sbuf.size());
memcpy(pac.buffer(), sbuf.data(), sbuf.size());
pac.buffer_consumed(sbuf.size());
msgpack::unpacked result;
while (pac.next(&result)) {
msgpack::object obj = result.get();
result.zone().release();
}
}
return 0;
}
Running this will leak until OOM killer dispatches the process.
Am I using the class wrong? The only documentation I can find (comments) say this is how it should be used.
Metadata
Metadata
Assignees
Labels
No labels