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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
hi,
any one has update on this?
Thanks,
Pavithra
Have you tried --library=posix.cfg?
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() {
}
Last edit: pavithra rani 2016-04-22
Cppcheck version 1.73 is the latest. Does the problem occur with that version?