Fix double fclose() on do_write(fd, xxx) failure
PATCH 3/3 Fix double fclose() on do_write(fd, xxx) failure
cppcheck reported:
[util/header.c:983]: (error) Used file that is not opened.
--- tools/perf/util/header.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/header.c +1 -0
@@ -955,6 +955,7 @@ static int write_topo_node(int fd, int node) }fclose (fp); + fp =NULL ; ret =do_write (fd, &mem_total,sizeof (u64));if (ret)
Signature · 1 line
1.7.11.7
Em Fri, Jan 25, 2013 at 11:22:17AM +0100, Thomas Jarosch escreveu:
Quoted 13 lines
cppcheck reported:
[util/header.c:983]: (error) Used file that is not opened.Signed-off-by Thomas Jarosch <[email protected]>--- tools/perf/util/header.c | 1 + 1 file changed, 1 insertion(+)tools/perf/util/header.c +0
-0
tools/perf/util/header.c static int write_topo_node(int fd, int node) · line 958
Quoted 4 lines
tools/perf/util/header.c +1
-0@@ -955,6 +955,7 @@ static int write_topo_node(int fd, int node) }fclose (fp); + fp =NULL ;
Ok, but what is the behaviour of fclose(NULL)? Is it defined?
- Arnaldo
Quoted 18 lines · On Friday, 25. January 2013 13:01:51 you wrote:
Em Fri, Jan 25, 2013 at 11:22:17AM +0100, Thomas Jarosch escreveu:
Quoted 17 lines
cppcheck reported:
[util/header.c:983]: (error) Used file that is not opened.Signed-off-by Thomas Jarosch <[email protected]>---
tools/perf/util/header.c | 1 + 1 file changed, 1 insertion(+)tools/perf/util/header.c +0
-0@@ -955,6 +955,7 @@ static int write_topo_node(int fd, int node) }
Quoted 7 lines
tools/perf/util/header.c static int write_topo_node(int fd, int node)
Quoted 3 lines
tools/perf/util/header.c +1
-0fclose (fp); + fp =NULL ;Ok, but what is the behaviour of fclose(NULL)? Is it defined?
- Arnaldo
Grrr, this is undefined behavior. Sorry. I always thought this is defined like free(NULL) but apparently it is not.
I'll send another version of the patch and also write to the man page maintainer to add a small hint to the fclose() man page.
Thomas