[PATCH] contrib/plugins/bbv.c: Check if file is NULL

Akihiko Odaki posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260307-bbv-v1-1-d5757d1deac8@rsg.ci.i.u-tokyo.ac.jp
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>
contrib/plugins/bbv.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] contrib/plugins/bbv.c: Check if file is NULL
Posted by Akihiko Odaki 1 month, 1 week ago
The file pointer can be NULL when e.g., opening the file failed.
vcpu_interval_exec() already implements a NULL-pointer check, but
plugin_exit() misses it. Handle the condition by adding the missing
check to plugin_exit().

Fixes: 0d279bec0f14 ("contrib/plugins: Add a plugin to generate basic block vectors")
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
 contrib/plugins/bbv.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/contrib/plugins/bbv.c b/contrib/plugins/bbv.c
index b9da6f815e36..5913cc6c637d 100644
--- a/contrib/plugins/bbv.c
+++ b/contrib/plugins/bbv.c
@@ -30,8 +30,13 @@ static uint64_t interval = 100000000;
 
 static void plugin_exit(qemu_plugin_id_t id, void *p)
 {
+    Vcpu *vcpu;
+
     for (int i = 0; i < qemu_plugin_num_vcpus(); i++) {
-        fclose(((Vcpu *)qemu_plugin_scoreboard_find(vcpus, i))->file);
+        vcpu = qemu_plugin_scoreboard_find(vcpus, i);
+        if (vcpu->file) {
+            fclose(vcpu->file);
+        }
     }
 
     g_hash_table_unref(bbs);

---
base-commit: ffcf1a7981793973ffbd8100a7c3c6042d02ae23
change-id: 20260307-bbv-2708e0023e0f

Best regards,
--  
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Re: [PATCH] contrib/plugins/bbv.c: Check if file is NULL
Posted by Pierrick Bouvier 1 month ago
On 3/6/26 7:22 PM, Akihiko Odaki wrote:
> The file pointer can be NULL when e.g., opening the file failed.
> vcpu_interval_exec() already implements a NULL-pointer check, but
> plugin_exit() misses it. Handle the condition by adding the missing
> check to plugin_exit().
> 
> Fixes: 0d279bec0f14 ("contrib/plugins: Add a plugin to generate basic block vectors")
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> ---
>   contrib/plugins/bbv.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 

This was merged into master (a8ff516c2f5ec05fb8b8bf4bceb88f49701f80d6).
Thank you for your contribution!

Regards,
Pierrick
Re: [PATCH] contrib/plugins/bbv.c: Check if file is NULL
Posted by Pierrick Bouvier 1 month ago
On 3/6/26 7:22 PM, Akihiko Odaki wrote:
> The file pointer can be NULL when e.g., opening the file failed.
> vcpu_interval_exec() already implements a NULL-pointer check, but
> plugin_exit() misses it. Handle the condition by adding the missing
> check to plugin_exit().
> 
> Fixes: 0d279bec0f14 ("contrib/plugins: Add a plugin to generate basic block vectors")
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> ---
>   contrib/plugins/bbv.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Re: [PATCH] contrib/plugins/bbv.c: Check if file is NULL
Posted by Philippe Mathieu-Daudé 1 month ago
On 7/3/26 04:22, Akihiko Odaki wrote:
> The file pointer can be NULL when e.g., opening the file failed.
> vcpu_interval_exec() already implements a NULL-pointer check, but
> plugin_exit() misses it. Handle the condition by adding the missing
> check to plugin_exit().
> 
> Fixes: 0d279bec0f14 ("contrib/plugins: Add a plugin to generate basic block vectors")
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> ---
>   contrib/plugins/bbv.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>