public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/114791] New: analyzer: file-leak not detected
@ 2024-04-21 5:38 urs at akk dot org
2024-04-21 5:39 ` [Bug analyzer/114791] " urs at akk dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: urs at akk dot org @ 2024-04-21 5:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791
Bug ID: 114791
Summary: analyzer: file-leak not detected
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: urs at akk dot org
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Build: x86_64-pc-linux-gnu
Created attachment 57998
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57998&action=edit
minimal test case
False negative -Wanalyzer-file-leak
gcc build from git @ ef2392236ec629351496d7f299d6a0956080e4d9
gcc-14 -D_DEFAULT_SOURCE -Wall -Wextra -fanalyzer -O2 -v -save-temps
-freport-bug -g -std=c11 -o fleak file-leak.c
doesn't give a warning but it should (value of fp may be overwritten before
released).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug analyzer/114791] analyzer: file-leak not detected
2024-04-21 5:38 [Bug analyzer/114791] New: analyzer: file-leak not detected urs at akk dot org
@ 2024-04-21 5:39 ` urs at akk dot org
2024-04-21 5:45 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: urs at akk dot org @ 2024-04-21 5:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791
--- Comment #1 from Urs Janßen <urs at akk dot org> ---
Created attachment 57999
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57999&action=edit
preprocessed example
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug analyzer/114791] analyzer: file-leak not detected
2024-04-21 5:38 [Bug analyzer/114791] New: analyzer: file-leak not detected urs at akk dot org
2024-04-21 5:39 ` [Bug analyzer/114791] " urs at akk dot org
@ 2024-04-21 5:45 ` pinskia at gcc dot gnu.org
2024-04-21 5:47 ` urs at akk dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-21 5:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Last reconfirmed| |2024-04-21
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug analyzer/114791] analyzer: file-leak not detected
2024-04-21 5:38 [Bug analyzer/114791] New: analyzer: file-leak not detected urs at akk dot org
2024-04-21 5:39 ` [Bug analyzer/114791] " urs at akk dot org
2024-04-21 5:45 ` pinskia at gcc dot gnu.org
@ 2024-04-21 5:47 ` urs at akk dot org
2024-04-21 5:54 ` pinskia at gcc dot gnu.org
2024-04-21 6:59 ` urs at akk dot org
4 siblings, 0 replies; 6+ messages in thread
From: urs at akk dot org @ 2024-04-21 5:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791
--- Comment #3 from Urs Janßen <urs at akk dot org> ---
Comment on attachment 57998
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57998
minimal test case
>#include <sys/types.h>
>#include <sys/stat.h>
>#include <unistd.h>
>#include <stdio.h>
>
>int main(void);
>
>int main(void) {
> FILE *fp = (FILE *) 0;
> int i = 0;
> static const char *list[] = { "/tmp/", "/tmp/a", "/tmp/b", NULL };
> struct stat st;
>
> while (list[i] != NULL) {
> if ((fp = fopen(list[i], "r")) != NULL) {
should be
if ((fp = fopen(list[i++], "r")) != NULL) {
> if (fstat(fileno(fp), &st) != -1) {
> if ((st.st_mode & (S_IFREG | S_IFLNK)) && st.st_size > 0L)
> break;
> }
> /* missing:
> fclose(fp);
> fp = NULL;
> here */
> }
> }
>
> if (fp)
> fclose(fp);
>}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug analyzer/114791] analyzer: file-leak not detected
2024-04-21 5:38 [Bug analyzer/114791] New: analyzer: file-leak not detected urs at akk dot org
` (2 preceding siblings ...)
2024-04-21 5:47 ` urs at akk dot org
@ 2024-04-21 5:54 ` pinskia at gcc dot gnu.org
2024-04-21 6:59 ` urs at akk dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-21 5:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Interesting, with -O0, there is a warning but that can be turned into a false
positive if you enable the "missing:" section.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug analyzer/114791] analyzer: file-leak not detected
2024-04-21 5:38 [Bug analyzer/114791] New: analyzer: file-leak not detected urs at akk dot org
` (3 preceding siblings ...)
2024-04-21 5:54 ` pinskia at gcc dot gnu.org
@ 2024-04-21 6:59 ` urs at akk dot org
4 siblings, 0 replies; 6+ messages in thread
From: urs at akk dot org @ 2024-04-21 6:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791
--- Comment #5 from Urs Janßen <urs at akk dot org> ---
-Wanalyzer-fd-leak has the same issue, no warning given for:
#define _DEFAULT_SOURCE 1
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
int main(void);
int main(void) {
int fd = -1;
int i = 0;
static const char *list[] = { "/tmp/", "/tmp/a", "/tmp/b", NULL };
struct stat st;
while (list[i] != NULL) {
if ((fd = open(list[i++], O_RDONLY)) != -1) {
if (fstat(fd, &st) != -1) {
if ((st.st_mode & (S_IFREG | S_IFLNK)) && st.st_size > 0L)
break;
}
#ifdef NO_FILE_LEAK
close(fd);
fd = -1;
#endif /* NO_FILE_LEAK */
}
}
if (fd != -1)
close(fd);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-04-21 6:59 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-21 5:38 [Bug analyzer/114791] New: analyzer: file-leak not detected urs at akk dot org
2024-04-21 5:39 ` [Bug analyzer/114791] " urs at akk dot org
2024-04-21 5:45 ` pinskia at gcc dot gnu.org
2024-04-21 5:47 ` urs at akk dot org
2024-04-21 5:54 ` pinskia at gcc dot gnu.org
2024-04-21 6:59 ` urs at akk dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).