Menu

Passing a double pointer to a function

Siddharth
2019-02-01
2019-02-02
  • Siddharth

    Siddharth - 2019-02-01

    I have this code here -

    custom_data_type *ptr;
    ptr = custom_data_allocator();
    custom_data_deallocator(&ptr);

    However, cppcheck complains -

    Deallocation of an auto-variable results in undefined behaviour." verbose="The deallocation of an auto-variable results in undefined behaviour. You should only free memory that has been allocated dynamically

    and if i use this , it works fine -
    custom_data_deallocator(ptr);

    However, this is clearly wrong (i am just testing cppheck without compilation) as my deallocator function expects a double pointer.

    Here is my .cfg snippet -
    <memory>
    <alloc>custom_data_allocator</alloc>
    <dealloc>custom_data_deallocator</dealloc>
    </memory>

    Please let me know if am missing anything. Also, these alloc/dealloc functions are third party.

    Thanks
    Siddharth

     

    Last edit: Siddharth 2019-02-01
    • Markus Elfring

      Markus Elfring - 2019-02-01
      • How do you think about to adjust the code markup in your message?
      • To which software version did you refer?
       
      • Siddharth

        Siddharth - 2019-02-01
        • Done.
        • I tried 1.83 and 1.86 versions.
         
  • Daniel Marjamäki

    Can you please try this configuration, I don't know maybe that works:

    <memory>
    <alloc>custom_data_allocator</alloc>
    <use>custom_data_deallocator</use>
    </memory>
    
     

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.