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

memory leak occurs when calling hs_compile #426

Open
jihunsuk opened this issue Dec 27, 2023 · 0 comments
Open

memory leak occurs when calling hs_compile #426

jihunsuk opened this issue Dec 27, 2023 · 0 comments

Comments

@jihunsuk
Copy link

jihunsuk commented Dec 27, 2023

I created a test module that uses HyperScan and checked for memory leaks using an application verifier.
However, when running hs_compile, a memory leak occurs.

The memory where the leak occurs is the MergeKey *mk allocated in the code below.

#ifndef _WIN32
         engine_groups[MergeKey(left, parents)].push_back(left);
#else
        // On windows, when passing MergeKey object into map 'engine_groups',
        // it will not be copied, but will be freed along with
        // engine_groups.clear().
        // If we construct MergeKey object on the stack, it will be destructed
        // on its life cycle ending, then on engine_groups.clear(), which
        // will cause is_block_type_valid() assertion error in MergeKey
        // destructor.
        MergeKey *mk = new MergeKey(left, parents);    // Memory Leak!!
        engine_groups[*mk].push_back(left);
#endif
    }

    vector<vector<left_id>> chunks;
    for (auto &raw_group : engine_groups | map_values) {
        chunk(move(raw_group), &chunks, MERGE_GROUP_SIZE_MAX);
    }
    engine_groups.clear();       // It is not released here.

I confirmed that memory leaks do not occur if I put the allocations in a separate list and free them when the function ends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant