Menu

fopen leak detected, fdopen leak not detected (cppcheck 2.5.1)

2021-07-11
2021-07-11
  • Jarkko Hietaniemi

    $ cat leak-fp.c
    #include <stdio.h>
    
    void leak_fp_fopen(char *fn) {
        fopen(fn, "r");
    }
    
    void leak_fp_fdopen(FILE *fp) {
        fdopen(fileno(fp), "r");
    }
    $ cppcheck leak-fp.c
    /Users/jhi/leak-fp.c:4:5: error: Return value of allocation function 'fopen' is not stored. [leakReturnValNotUsed]
        fopen(fn, "r");
        ^
    $ cppcheck --version
    Cppcheck 2.5
    
     
  • orbitcowboy

    orbitcowboy - 2021-07-11

    Did you use " --library=posix", at commandline? It should provide information of fdopen to Cppcheck.

     

Log in to post a comment.