Menu

Wrong "Mismatching allocation and deallocation" warning

Denis
2020-03-17
2021-01-28
  • Denis

    Denis - 2020-03-17

    The following example causes the wrong "Mismatching allocation and deallocation" warning

    #include <stdlib.h> //aligned_alloc
    
    #define _aligned_free free
    inline void* _aligned_malloc(size_t size, size_t alignment)
    {
        if(size % alignment)
            size += alignment - size % alignment;
        return aligned_alloc(alignment, size);
    }
    
    int main()
    {
        void* ptr = _aligned_malloc(100, 64);
        _aligned_free(ptr);
        return 0;
    }
    
     
  • CHR

    CHR - 2021-01-26

    I can reproduce this with v2.3. Using free() with aligned_alloc() seems to be correct: https://en.cppreference.com/w/c/memory/aligned_alloc

     
  • CHR

    CHR - 2021-01-28

    Upon further inspection, this is not related to aligned_alloc per se. The problem lies with _aligned_malloc in windows.cfg, and the warning goes away when I specify --platform=unix64. I don't think the code would compile if there were two _aligned_malloc() in the global namespace, i.e. on Windows. So not a bug imho.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.