Menu

cppcheck does not report any error if there is a miss in close() system call

2016-04-21
2016-04-23
  • pavithra rani

    pavithra rani - 2016-04-21

    Hi,
    I do not know why cppcheck is not showing resource leak when close(fd) system call was not made.
    Resource Leak is thrown only when fclose is missing.

    .#define FNAME "a.txt"
    int main()
    {
    FILE *fp;
    int fd;
    fp=fopen("b.txt","w+");
    fd=open(FNAME,O_RDONLY,0);
    return 0;
    }

    cppcheck --enable=all Myopen.cc
    Checking Myopen.cc...
    [Myopen.cc:12]: (style) Variable 'fp' is assigned a value that is never used.
    [Myopen.cc:13]: (style) Variable 'fd' is assigned a value that is never used.
    [Myopen.cc:14]: (error) Resource leak: fp
    Checking usage of global functions..
    (information) Cppcheck cannot find all the include files (use --check-config for details)

    please reply if any one is aware of this.
    Thanks,
    Pavithra

     
  • pavithra rani

    pavithra rani - 2016-04-22

    hi,

    any one has update on this?

    Thanks,
    Pavithra

     
  • Mr. X

    Mr. X - 2016-04-22

    Have you tried --library=posix.cfg?

     
  • pavithra rani

    pavithra rani - 2016-04-22

    hey thanks:) I tired with above option too. Installed latest cppcheck 1.72 and included library option Still no error is reported.

    Command Line:
    cppcheck --enable=all --library=/usr/bin/cfg/posix.cfg --std=posix ConfigFileStream.cc

    Code snippet:
    open() system call is invoked in constructor , also file descriptor is not created here.

    configFileStream::configFileStream(String configFileName,String release, char separator, AxBoolean oneDomain)
    :ifstream() {

        open(configFileName);
         .
         .
         .
    

    }

     

    Last edit: pavithra rani 2016-04-22
  • raynebc

    raynebc - 2016-04-23

    Cppcheck version 1.73 is the latest. Does the problem occur with that version?

     

Log in to post a comment.