Menu

Wrong (error) Resource/Memory leak message

2018-11-18
2018-11-18
  • Yurii Putin

    Yurii Putin - 2018-11-18

    Hi. some code snippets in my program cause error messages. I think that is wrong. For example:

    int main(int argc, char* argv[])
    {

    char *fname = "file.txt";
    FILE *f = NULL;
    char *r = NULL;
    
    while ((f = fopen(fname,"rt"))!=NULL)// (error) Resource leak: f [resourceLeak]  ???
    {
        /* do something */
        fclose(f);
        // if (condition) break;
    }
    
    while ((r = (char*)malloc(sizeof(*r)*100))!=NULL)// (error) Memory leak: r [memleak]  ???
    {
        /* do something */
        free(r);
        // if (condition) break;
    }
    
    return 0;
    

    }

     
  • Daniel Marjamäki

    Thanks! I created this ticket https://trac.cppcheck.net/ticket/8854

     

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.