selftests/bpf: close the file descriptor to avoid resource leaks
Subsystems (3)
PATCH 1/1 selftests/bpf: close the file descriptor to avoid resource leaks
Static Analyis for bench_htab_mem.c with cppcheck:error tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak] tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]
fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 1 + tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1 -0
@@ -281,6 +281,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) got =read (fd, buf,sizeof (buf) -1 );if (got <=0 ) { *value =0 ; +close (fd);return ; } buf[got] =0 ;
tools/testing/selftests/bpf/prog_tests/sk_assign.c +3 -1
@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else
Signature · 1 line
2.43.0
Quoted 10 lines · Malaya Kumar Rout
Static Analyis for
bench_htab_mem.cwith cppcheck:errortools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
Signed-off-by Malaya Kumar Rout <[email protected]>
The right subject prefix for the patch should be "[PATCH bpf-next]", however, it seems there is no need or no reason to respin the patch.
Quoted 33 lines
--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 1 + tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-0@@ -281,6 +281,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) got =read (fd, buf,sizeof (buf) -1 );if (got <=0 ) { *value =0 ; +close (fd);return ; } buf[got] =0 ;tools/testing/selftests/bpf/prog_tests/sk_assign.c +3
-1@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else
Quoted 21 lines · Malaya Kumar Rout
Static Analyis for
bench_htab_mem.cwith cppcheck:errortools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
Signed-off-by Malaya Kumar Rout <[email protected]>--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 1 + tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)tools/testing/selftests/bpf/benchs/bench_htab_mem.c +0
-0
tools/testing/selftests/bpf/benchs/bench_htab_mem.c static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) · line 281
Quoted 1 line
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +0
-0@@ -281,6 +281,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) got =read (fd, buf,sizeof (buf) -1 );
It could be a bit cleaner to add close(fd) here and drop the one we have at the end of the function.
pw-bot: cr
Quoted 11 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-0if (got <=0 ) { *value =0 ; +close (fd);return ; } buf[got] =0 ;tools/testing/selftests/bpf/prog_tests/sk_assign.c +0
-0
tools/testing/selftests/bpf/prog_tests/sk_assign.c configure_stack(void) · line 41
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c +2
-1@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);
this one looks good
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c +1
-1return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0
Quoted 19 lines · Andrii Nakryiko
Quoted 16 lines · Malaya Kumar Rout
Static Analyis for
bench_htab_mem.cwith cppcheck:errortools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
Signed-off-by Malaya Kumar Rout <[email protected]>--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 1 + tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)
Quoted 10 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) · line 281
Quoted 6 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +0
-0@@ -281,6 +281,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) got =read (fd, buf,sizeof (buf) -1 );It could be a bit cleaner to add close(fd) here and drop the one we have at the end of the function.
Here, close(fd) is now positioned within the error handling block, guaranteeing that
the file descriptor will be closed prior to returning from the function in the event of a read error.
Meanwhile, the final close(fd) at the end of the function is retained for successful execution,
thereby avoiding any potential resource leaks.
Hence, It is essential to add the close(fd) in both locations to prevent resource leakage.
Quoted 30 lines
pw-bot: cr
Quoted 11 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-0if (got <=0 ) { *value =0 ; +close (fd);return ; } buf[got] =0 ;tools/testing/selftests/bpf/prog_tests/sk_assign.c +0
-0tools/testing/selftests/bpf/prog_tests/sk_assign.c configure_stack(void) · line 41
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c +2
-1@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);this one looks good
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c +1
-1return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0
Hi,
Quoted 28 lines · malaya kumar rout
Quoted 17 lines · Andrii Nakryiko
Quoted 15 lines · Malaya Kumar Rout
Static Analyis for
bench_htab_mem.cwith cppcheck:errortools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
Signed-off-by Malaya Kumar Rout <[email protected]>--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 1 + tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)Quoted 9 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) · line 281
Quoted 6 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +0
-0@@ -281,6 +281,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) got =read (fd, buf,sizeof (buf) -1 );It could be a bit cleaner to add close(fd) here and drop the one we have at the end of the function.
Quoted 9 lines
Here, close(fd) is now positioned within the error handling block, guaranteeing that
the file descriptor will be closed prior to returning from the function in the event of a read error.
Meanwhile, the final close(fd) at the end of the function is retained for successful execution,
thereby avoiding any potential resource leaks.
Hence, It is essential to add the close(fd) in both locations to prevent resource leakage.
I think Andrii was proposing the following solution:
{
/* ...... */
got = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (got <= 0) {
*value = 0;
return;
}
buf[got] = 0;
*value = strtoull(buf, NULL, 0);
}
It only invokes close(fd) once to handle both the failed case and the successful case.
Quoted 31 lines
Quoted 13 lines
pw-bot: cr
Quoted 10 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-0if (got <=0 ) { *value =0 ; +close (fd);return ; } buf[got] =0 ;tools/testing/selftests/bpf/prog_tests/sk_assign.c +0
-0Quoted 17 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c configure_stack(void) · line 41
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c +2
-1@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);this one looks good
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c +1
-1return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0
.
Quoted 57 lines · Hou Tao
Hi,
Quoted 28 lines · malaya kumar rout
Quoted 17 lines · Andrii Nakryiko
Quoted 15 lines · Malaya Kumar Rout
Static Analyis for
bench_htab_mem.cwith cppcheck:errortools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
Signed-off-by Malaya Kumar Rout <[email protected]>--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 1 + tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-)Quoted 9 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) · line 281
Quoted 6 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +0
-0@@ -281,6 +281,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) got =read (fd, buf,sizeof (buf) -1 );It could be a bit cleaner to add close(fd) here and drop the one we have at the end of the function.
Quoted 9 lines
Here, close(fd) is now positioned within the error handling block, guaranteeing that
the file descriptor will be closed prior to returning from the function in the event of a read error.
Meanwhile, the final close(fd) at the end of the function is retained for successful execution,
thereby avoiding any potential resource leaks.
Hence, It is essential to add the close(fd) in both locations to prevent resource leakage.I think Andrii was proposing the following solution:
{ /* ...... */ got = read(fd, buf, sizeof(buf) - 1); close(fd); if (got <= 0) { *value = 0; return; } buf[got] = 0; *value = strtoull(buf, NULL, 0); }
Quoted 3 lines
It only invokes close(fd) once to handle both the failed case and the successful case.
Quoted 1 line
I greatly appreciate your insightful feedback on the review.
I will proceed to share the updated patch that includes the modifications.
Quoted 31 lines
Quoted 30 lines
Quoted 12 lines
pw-bot: cr
Quoted 10 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-0if (got <=0 ) { *value =0 ; +close (fd);return ; } buf[got] =0 ;tools/testing/selftests/bpf/prog_tests/sk_assign.c +0
-0Quoted 17 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c configure_stack(void) · line 41
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c +2
-1@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);this one looks good
Quoted 8 lines
tools/testing/selftests/bpf/prog_tests/sk_assign.c +1
-1return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0
.
Static Analyis for bench_htab_mem.c with cppcheck:error tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak] tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]
fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1 -2
@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;
@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)
tools/testing/selftests/bpf/prog_tests/sk_assign.c +3 -1
@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else
Signature · 1 line
2.43.0
Hou Tao
Acked-byQuoted 10 lines · Malaya Kumar Rout
Static Analyis for
bench_htab_mem.cwith cppcheck:errortools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
Signed-off-by Malaya Kumar Rout <[email protected]>
It will be better to resend the patch and change the subject prefix to "[PATCH RESEND bpf-next v2]" instead of "[PATCH v2]".
Quoted 42 lines
--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-2@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)tools/testing/selftests/bpf/prog_tests/sk_assign.c +3
-1@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else
Static Analyis for bench_htab_mem.c with cppcheck:error tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak] tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]
fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1 -2
@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;
@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)
tools/testing/selftests/bpf/prog_tests/sk_assign.c +3 -1
@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else
Signature · 1 line
2.43.0
Quoted 2 lines · Malaya Kumar Rout
Static Analyis for
bench_htab_mem.cwith cppcheck:error
typo: analysis (lower case and typo)
you can also make into a bit more human-readable sentence:
"Static analysis found an issue in bench_htab_mem.c:
Quoted 7 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
"Fix the issue by closing" (capitalization, single space between words
Quoted 7 lines
Signed-off-by Malaya Kumar Rout <[email protected]>--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)
For some reason this patch didn't make it into our Patchworks system, so we can't easily apply it. Please fix the above commit issues and resubmit, hopefully this time it goes through just fine.
Quoted 40 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-2@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)tools/testing/selftests/bpf/prog_tests/sk_assign.c +3
-2@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0
Quoted 31 lines · Andrii Nakryiko
Quoted 2 lines · Malaya Kumar Rout
Static Analyis for
bench_htab_mem.cwith cppcheck:errortypo: analysis (lower case and typo)
you can also make into a bit more human-readable sentence:
"Static analysis found an issue in
bench_htab_mem.c:Quoted 7 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3:
error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3:
error: Resource leak: tc [resourceLeak]fix the issue by closing the file descriptor (fd & tc) when read & fgets operation fails.
"Fix the issue by closing" (capitalization, single space between words
Quoted 7 lines
Signed-off-by Malaya Kumar Rout <[email protected]>--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)
Quoted 3 lines
For some reason this patch didn't make it into our Patchworks system, so we can't easily apply it. Please fix the above commit issues and resubmit, hopefully this time it goes through just fine.
I thought it was a maintenance issue with patchwork, but it's probably something else.
I'm guessing your cc list confuses pw bot.
Pls drop linux-kselftest@vger and lkml@vger and keep bpf@vger only.
Static analysis found an issue in bench_htab_mem.c
cppcheck output before this patch:tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3: error: Resource leak: fd [resourceLeak] tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3: error: Resource leak: tc [resourceLeak]
cppcheck output after this patch:
No resource leaks found
Fix the issue by closing the file descriptors fd and tc.
--- tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1 -2
@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;
@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)
tools/testing/selftests/bpf/prog_tests/sk_assign.c +3 -1
@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else
Signature · 1 line
2.43.0
Quoted 7 lines · Malaya Kumar Rout
Static analysis found an issue in
bench_htab_mem.ccppcheck output before this patch:
tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3: error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3: error: Resource leak: tc [resourceLeak]
Quoted 7 lines
cppcheck output after this patch:
No resource leaks foundFix the issue by closing the file descriptors fd and tc.
Signed-off-by Malaya Kumar Rout <[email protected]>---
I still don't see this patch in our Patchworks.
But I noticed that the subject is:
RE:[PATCH RESEND bpf-next v3] selftests/bpf: close the file descriptor to avoid resource leaks
and there is
In-Reply-To: <CAADnVQJbBOK25Fx3zEG-ZH=zTFRfPNQye673b5TnpdTdMEXAUA@mail.gmail.com>
email header, so I suspect bot ignores this because it's a reply.
Please send it as a stand-alone email with git send-email, hopefully that works.
Quoted 44 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-2@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)tools/testing/selftests/bpf/prog_tests/sk_assign.c +3
-2@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0
Malaya Kumar Rout
Ph. No: +91-9778203508
+91-7008245249
Quoted 25 lines · Andrii Nakryiko
Quoted 7 lines · Malaya Kumar Rout
Static analysis found an issue in
bench_htab_mem.ccppcheck output before this patch:
tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3: error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3: error: Resource leak: tc [resourceLeak]Quoted 7 lines
cppcheck output after this patch:
No resource leaks foundFix the issue by closing the file descriptors fd and tc.
Signed-off-by Malaya Kumar Rout <[email protected]>---
I still don't see this patch in our Patchworks.
But I noticed that the subject is:
RE:[PATCH RESEND bpf-next v3] selftests/bpf: close the file descriptor to avoid resource leaks
Quoted 9 lines
and there is
In-Reply-To: <CAADnVQJbBOK25Fx3zEG-ZH=zTFRfPNQye673b5TnpdTdMEXAUA@mail.gmail.com>
email header, so I suspect bot ignores this because it's a reply.
Please send it as a stand-alone email with
git send-email, hopefully that works.
I have shared a stand-alone email with 'git send-email'.Kindly confirm at your earliest convenience. If any issues arise again, please permit me to share two separate patches, as we have modifications in two distinct files.
Quoted 44 lines
Quoted 44 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-2@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)tools/testing/selftests/bpf/prog_tests/sk_assign.c +3
-2@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0
Quoted 38 lines · malaya kumar rout
Malaya Kumar Rout
Ph. No: +91-9778203508+91-7008245249Quoted 31 lines · Andrii Nakryiko
Quoted 7 lines · Malaya Kumar Rout
Static analysis found an issue in
bench_htab_mem.ccppcheck output before this patch:
tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3: error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3: error: Resource leak: tc [resourceLeak]Quoted 7 lines
cppcheck output after this patch:
No resource leaks foundFix the issue by closing the file descriptors fd and tc.
Signed-off-by Malaya Kumar Rout <[email protected]>---
I still don't see this patch in our Patchworks.
But I noticed that the subject is:
RE:[PATCH RESEND bpf-next v3] selftests/bpf: close the file descriptor to avoid resource leaks
and there is
In-Reply-To: <CAADnVQJbBOK25Fx3zEG-ZH=zTFRfPNQye673b5TnpdTdMEXAUA@mail.gmail.com>
email header, so I suspect bot ignores this because it's a reply.
Quoted 8 lines
Quoted 3 lines
Please send it as a stand-alone email with
git send-email, hopefully that works.I have shared a stand-alone email with 'git send-email'.Kindly confirm at your earliest convenience. If any issues arise again, please permit me to share two separate patches, as we have modifications in two distinct files.
Yes, this time email arrived into Patchworks, but you had pclose -> close mistake, please fix, test, and resubmit.
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-2@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)tools/testing/selftests/bpf/prog_tests/sk_assign.c +3
-2@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0
Quoted 44 lines · Andrii Nakryiko
Quoted 41 lines · malaya kumar rout
Malaya Kumar Rout
Ph. No: +91-9778203508+91-7008245249Quoted 34 lines · Andrii Nakryiko
Quoted 7 lines · Malaya Kumar Rout
Static analysis found an issue in
bench_htab_mem.ccppcheck output before this patch:
tools/testing/selftests/bpf/benchs/bench_htab_mem.c:284:3: error: Resource leak: fd [resourceLeak]tools/testing/selftests/bpf/prog_tests/sk_assign.c:41:3: error: Resource leak: tc [resourceLeak]Quoted 7 lines
cppcheck output after this patch:
No resource leaks foundFix the issue by closing the file descriptors fd and tc.
Signed-off-by Malaya Kumar Rout <[email protected]>---
I still don't see this patch in our Patchworks.
But I noticed that the subject is:
RE:[PATCH RESEND bpf-next v3] selftests/bpf: close the file descriptor to avoid resource leaks
and there is
In-Reply-To: <CAADnVQJbBOK25Fx3zEG-ZH=zTFRfPNQye673b5TnpdTdMEXAUA@mail.gmail.com>
email header, so I suspect bot ignores this because it's a reply.
Please send it as a stand-alone email with
git send-email, hopefully that works.
Quoted 9 lines
Quoted 5 lines
I have shared a stand-alone email with 'git send-email'.Kindly confirm at your earliest convenience. If any issues arise again, please permit me to share two separate patches, as we have modifications in two distinct files.
Yes, this time email arrived into Patchworks, but you had pclose -> close mistake, please fix, test, and resubmit.
I have submitted the patch in a separate email once more, following thorough testing.
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
Quoted 44 lines
tools/testing/selftests/bpf/benchs/bench_htab_mem.c | 3 +-- tools/testing/selftests/bpf/prog_tests/sk_assign.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-)tools/testing/selftests/bpf/benchs/bench_htab_mem.c +1
-2@@ -279,6 +279,7 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) } got =read (fd, buf,sizeof (buf) -1 ); +close (fd);if (got <=0 ) { *value =0 ;return ;@@ -286,8 +287,6 @@ static void htab_mem_read_mem_cgrp_file(const char *name, unsigned long *value) buf[got] =0 ; *value =strtoull (buf,NULL ,0 ); - -close (fd); }static void htab_mem_measure (struct bench_res *res)tools/testing/selftests/bpf/prog_tests/sk_assign.c +3
-2@@ -37,8 +37,10 @@ configure_stack(void) tc =popen ("tc -V" ,"r" );if (CHECK_FAIL (!tc))return false; -if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) +if (CHECK_FAIL (!fgets (tc_version,sizeof (tc_version), tc))) { +pclose (tc);return false; + }if (strstr (tc_version,", libbpf " )) prog ="test_sk_assign_libbpf.bpf.o" ;else --2.43.0