Skip to contentSkip to conversation

selftests: kvm: fix mismatched fclose() after popen()

PATCH Superseded Shuah Khan 1 participant 2 messages Oct 21, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Shuah Khan

author maintainer
#0 lore raw

PATCH 1/1 selftests: kvm: fix mismatched fclose() after popen()

get_warnings_count() foes fclose() using File * returned from popen(). Fix it to call pclose() as it should.

tools/testing/selftests/kvm/x86_64/mmio_warning_test
x86_64/mmio_warning_test.c: In function ‘get_warnings_count’:
x86_64/mmio_warning_test.c:87:9: warning: ‘fclose’ called on pointer returned from a mismatched allocation function [-Wmismatched-dealloc]

   87 |         fclose(f);
      |         ^~~~~~~~~
x86_64/mmio_warning_test.c:84:13: note: returned from ‘popen’
   84 |         f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/x86_64/mmio_warning_test.c +1 -1
index 8039e1eff938..9f55ccd169a1 100644
@@ -84,7 +84,7 @@ int get_warnings_count(void)
 	f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
 	if (fscanf(f, "%d", &warnings) < 1)
 		warnings = 0;
-	fclose(f);
+	pclose(f);
 
 	return warnings;
 }
Signature · 1 line
2.32.0
author maintainer
#1 lore raw
Quoted 1 line · Shuah Khan

get_warnings_count() foes fclose() using File * returned from popen().

Oops should have been "does". Sending v2 with that change now.

Quoted 22 lines

Fix it to call pclose() as it should.

tools/testing/selftests/kvm/x86_64/mmio_warning_test
x86_64/mmio_warning_test.c: In function ‘get_warnings_count’:
x86_64/mmio_warning_test.c:87:9: warning: ‘fclose’ called on pointer returned from a mismatched allocation function [-Wmismatched-dealloc]

    87 |         fclose(f);
       |         ^~~~~~~~~
x86_64/mmio_warning_test.c:84:13: note: returned from ‘popen’
    84 |         f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
  tools/testing/selftests/kvm/x86_64/mmio_warning_test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/kvm/x86_64/mmio_warning_test.c +0 -0
index 8039e1eff938..9f55ccd169a1 100644

tools/testing/selftests/kvm/x86_64/mmio_warning_test.c int get_warnings_count(void) · line 90

Quoted 8 lines
tools/testing/selftests/kvm/x86_64/mmio_warning_test.c +1 -1
@@ -84,7 +84,7 @@ int get_warnings_count(void)
  	f = popen("dmesg | grep \"WARNING:\" | wc -l", "r");
  	if (fscanf(f, "%d", &warnings) < 1)
  		warnings = 0;
-	fclose(f);
+	pclose(f);
 
  	return warnings;
  }

thanks,
-- Shuah