Commit bb1a8c30 authored by Dominik Charousset's avatar Dominik Charousset

Fix leak in message_data::copy

parent a2862f39
......@@ -32,7 +32,7 @@ public:
// nop
}
explicit typed_message_view(message& msg) : ptr_(&msg.data()) {
explicit typed_message_view(message& msg) : ptr_(msg.ptr()) {
// nop
}
......
......@@ -69,6 +69,7 @@ message_data* message_data::copy() const {
auto& meta = gmos[id];
// TODO: exception handling.
meta.copy_construct(dst, src);
++ptr->constructed_elements_;
src += meta.padded_size;
dst += meta.padded_size;
}
......
......@@ -61,6 +61,24 @@ CAF_TEST(messages allow index - based access) {
CAF_CHECK_EQUAL(msg.cdata().get_reference_count(), 1u);
}
CAF_TEST(message detach their content on mutating access) {
CAF_MESSAGE("Given to messages pointing to the same content.");
auto msg1 = make_message("one", uint32_t{1});
auto msg2 = msg1;
CAF_CHECK_EQUAL(msg1.cdata().get_reference_count(), 2u);
CAF_CHECK_EQUAL(msg1.cptr(), msg2.cptr());
CAF_MESSAGE("When calling a non-const member function of message.");
msg1.ptr();
CAF_MESSAGE("Then the messages point to separate contents but remain equal.");
CAF_CHECK_NOT_EQUAL(msg1.cptr(), msg2.cptr());
CAF_CHECK_EQUAL(msg1.cdata().get_reference_count(), 1u);
CAF_CHECK_EQUAL(msg2.cdata().get_reference_count(), 1u);
CAF_CHECK(msg1.match_elements<std::string, uint32_t>());
CAF_CHECK(msg2.match_elements<std::string, uint32_t>());
CAF_CHECK_EQUAL(msg1.get_as<std::string>(0), msg2.get_as<std::string>(0));
CAF_CHECK_EQUAL(msg1.get_as<uint32_t>(1), msg2.get_as<uint32_t>(1));
}
CAF_TEST(compare_custom_types) {
s2 tmp;
tmp.value[0][1] = 100;
......
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