intel/hyperscan

memory leak occurs when calling hs_compile

jihunsuk opened this issue · 0 comments

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.