Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leak of Union #71

Closed
mdavidsaver opened this issue Jul 30, 2024 · 1 comment · Fixed by #77
Closed

Leak of Union #71

mdavidsaver opened this issue Jul 30, 2024 · 1 comment · Fixed by #77
Assignees
Labels
bug Something isn't working

Comments

@mdavidsaver
Copy link
Member

mdavidsaver commented Jul 30, 2024

The fix in 92fb0a4 (for #38) is incomplete and incorrect for Union or Any fields. I think it creates a reference loop leading to a resource leak. Reported as epics-base/p4p#147 .

export EVENT_NOEPOLL=1
valgrind --leak-check=full --suppressions=pvxs.supp \
 ./bin/linux-x86_64-debug/pvxmonitor -# 5 test:image
...
==677865== 24 bytes in 3 blocks are definitely lost in loss record 31 of 111
==677865==    at 0x484220F: operator new[](unsigned long) (vg_replace_malloc.c:640)
==677865==    by 0x48DB3B3: pvxs::shared_array<pvxs::Value, void>::shared_array(unsigned long) (sharedArray.h:282)
==677865==    by 0x490BA69: pvxs::impl::from_wire_field(pvxs::impl::Buffer&, std::map<unsigned short, std::vector<pvxs::impl::FieldDesc, std::allocator<pvxs::impl::FieldDesc> >, std::less<unsigned short>, std::allocator<std::pair<unsigned short const, std::vector<pvxs::impl::FieldDesc, std::allocator<pvxs::impl::FieldDesc> > > > >&, pvxs::impl::FieldDesc const*, std::shared_ptr<pvxs::impl::FieldStorage> const&) (dataencode.cpp:610)
==677865==    by 0x490C5AB: pvxs::impl::from_wire_valid(pvxs::impl::Buffer&, std::map<unsigned short, std::vector<pvxs::impl::FieldDesc, std::allocator<pvxs::impl::FieldDesc> >, std::less<unsigned short>, std::allocator<std::pair<unsigned short const, std::vector<pvxs::impl::FieldDesc, std::allocator<pvxs::impl::FieldDesc> > > > >&, pvxs::Value&) (dataencode.cpp:723)
==677865==    by 0x49E9805: pvxs::client::Connection::handle_MONITOR() (clientmon.cpp:550)
...
@mdavidsaver
Copy link
Member Author

pvxs/src/data.cpp

Lines 1233 to 1239 in 46ee1a6

case StoreType::Compound:
{
std::shared_ptr<impl::FieldStorage> sstore(Value::Helper::store(dlt),
src);
auto& dfld(dst->as<Value>());
Value::Helper::set_desc(dfld, &desc[i]);
Value::Helper::store(dfld) = std::move(sstore);

dlt should not be referenced within this loop. This leads to line 1239 creating a reference loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant