Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix leak in the buffer vectorMembers when reading SIO frames #589

Merged
merged 3 commits into from
Apr 19, 2024

Conversation

jmcarcell
Copy link
Member

@jmcarcell jmcarcell commented Apr 18, 2024

BEGINRELEASENOTES

  • Fix leak in the buffer vectorMembers when reading SIO frames

ENDRELEASENOTES

The leak happens because at the time of this emplace_back, there is already an element in the vector with the string corresponding to that vector member. Then, the indexing will only find the first instance and this second one is leaked, so the fix is to check before and only if it isn't there add it. I think this is added for the first time in https://github.com/AIDASoft/podio/blob/master/python/templates/SIOBlock.cc.jinja2#L92

This helps with the read_frame_sio test. Before:

SUMMARY: AddressSanitizer: 12714 byte(s) leaked in 482 allocation(s).

After:

SUMMARY: AddressSanitizer: 11786 byte(s) leaked in 445 allocation(s).

I'm not sure if we need a test since read_frame_sio would be the one, once it doesn't have any leaks. Otherwise to reproduce we just have to read a frame with a collection with a vector member.

I did this one because after this I have a version of #583 without leaks.

Comment on lines 44 to 56
bool found;
{% for member in VectorMembers %}
m_buffers.vectorMembers->emplace_back("{{ member.full_type }}", new std::vector<{{ member.full_type }}>());
found = false;
for (const auto& [first, second] : *m_buffers.vectorMembers) {
if (first == "{{ member.full_type }}") {
found = true;
break;
}
}
if (!found) {
m_buffers.vectorMembers->emplace_back("{{ member.full_type }}", new std::vector<{{ member.full_type }}>());
}
{% endfor %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC all of this can go, because the buffers at this point already have these vector members set correctly from here:

{% for member in VectorMembers %}
readBuffers.vectorMembers->emplace_back("{{ member.full_type }}", new std::vector<{{ member.full_type }}>);
{% endfor %}

No idea, why this got to here and why it seems to pass all sanitizers and tests. (probably because it's not properly tested).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that looks to be correct, no more leaks related to that.

@tmadlener tmadlener merged commit 3919f8b into AIDASoft:master Apr 19, 2024
16 of 18 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants