Menu

Passing a double pointer and freeing it

Siddharth
2019-02-13
2019-02-13
  • Siddharth

    Siddharth - 2019-02-13

    I have this code -

    #include <stdlib.h>
    
    static void test(int **);
    
    int main() {
        int *ptr = NULL;
        ptr = malloc(100);
        test(&ptr);
        return 0;
    }
    
    static void test(int **ptr) {
       // free(*ptr);
    }
    

    cppcheck doesn't report a memory leak, not sure why not - am i missing anything here ?

    Thanks
    Siddharth

     

    Last edit: Siddharth 2019-02-13
  • Siddharth

    Siddharth - 2019-02-13
     

    Last edit: Siddharth 2019-02-13
  • Daniel Marjamäki

     

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.