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

dxcisense: Allocate "TM" classes using IMalloc instead of new #3258

Merged
merged 1 commit into from
Nov 17, 2020

Commits on Nov 12, 2020

  1. dxcisense: Allocate "TM" classes using IMalloc instead of new

    When running valgrind over a program using `DxcIntelliSense` (to
    validate our own deallocations [1]) a bunch of mismatching `new` with
    `free()` show up:
    
        Mismatched free() / delete / delete []
           at 0x483B9AB: free (vg_replace_malloc.c:538)
           by 0x52B06A8: IMalloc::Free(void*) (WinAdapter.cpp:34)
           by 0x6DC7D19: DxcTranslationUnit::Release() (dxcisenseimpl.h:308)
           by 0x14278E: com_rs::unknown::IUnknown::release (unknown.rs:55)
           [...]
         Address 0x4c3c930 is 0 bytes inside a block of size 40 alloc'd
           at 0x483B07F: operator new(unsigned long, std::nothrow_t const&) (vg_replace_malloc.c:385)
           by 0x6DC06EB: DxcIndex::ParseTranslationUnit(char const*, char const* const*, int, IDxcUnsavedFile**, unsigned int, DxcTranslationUnitFlags, IDxcTranslationUnit**) (dxcisenseimpl.cpp:1192)
           by 0x13020A: hassle_rs::intellisense::ffi::IDxcIndex::parse_translation_unit (macros.rs:108)
           by 0x119B74: hassle_rs::intellisense::wrapper::DxcIndex::parse_translation_unit (wrapper.rs:101)
           [...]
    
    And so on for the other intellisense classes.  All these classes have
    `DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL` which deallocates `this` on the
    associated `m_pMalloc` with `free()`:
    
        The "TM" version keep an IMalloc field that, if not null, indicate
        ownership of 'this' and of any allocations used during release.
    
    Yet are allocated using `new`, resulting in this mismatch.  The solution
    is to follow a similar approach as the introduction of `IMalloc` to
    `DxcIntelliSense` in d5bb308 by rewriting all classes to take an
    `IMalloc *` in the constructor and invoking it either through `::Alloc`
    from `DXC_MICROCOM_TM_ALLOC` or `CreateOnMalloc`.
    
    [1]: microsoft#3250 (comment)
    MarijnS95 committed Nov 12, 2020
    Configuration menu
    Copy the full SHA
    b181980 View commit details
    Browse the repository at this point in the history