pdidev / pdi

The PDI Data Interface
https://pdi.dev
BSD 3-Clause "New" or "Revised" License
6 stars 0 forks source link

Memory leak in Ref #418

Closed jbigot closed 2 months ago

jbigot commented 2 years ago

In GitLab by @ksiero on Mar 14, 2022, 13:45

I have found memory leak in ref_any.h:336:

link(new Referenced_data(data, freefunc, std::move(concrete_type), readable,  writable));
void link(Referenced_data* content)
{
    assert(!m_content);
    if (!content || !content->m_data) return; // null ref
    if (R && content->m_buffer->m_read_locks) return;
    if (W && content->m_buffer->m_write_locks) return;
    ...
jbigot commented 2 years ago

can you say a bit more?

jbigot commented 2 years ago

In GitLab by @ksiero on Mar 15, 2022, 12:28

When link method calls return; allocated memory by new Referenced_data is not deleted.

jbigot commented 2 years ago

It is stored in m_content on line 669

        m_content = content;

This is freed by unlink on line 652

        if (!m_content->m_owners) delete m_content;

Do I miss something?

jbigot commented 2 years ago

In GitLab by @ksiero on Mar 16, 2022, 11:31

Yes, it stored in m_content, but after all 3 of right access checks. What if before one of 3 condition fails?

jbigot commented 2 years ago

good catch! I missed it.

We should store the pointer in a unique_ptr and use release to assign it to m_content

jbigot commented 2 years ago

In GitLab by @ksiero on Mar 31, 2022, 14:22

mentioned in commit 170a39e018cd9b0f0ba0b549f066ae41e94c9ab3

jbigot commented 2 years ago

In GitLab by @ksiero on Apr 1, 2022, 09:41

mentioned in commit 73b4415b11891e852739351135872a71d204c1b3