All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qemu-pr-helper: do not free reply when multipath_process_cmd() fails
@ 2026-10-19 15:33 Stefan Hajnoczi
  2026-10-19 16:19 ` Eric Blake
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Hajnoczi @ 2026-10-19 15:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: Paolo Bonzini, qemu-block, Fam Zheng, Stefan Hajnoczi,
	Benjamin Marzinski, kwolf, eblake

Kevin Wolf pointed out that the multipath_process_cmd() documentation
only defines the value of reply on success. Don't touch it when the
function returns -1.

The libmpathcmd implementation as of c78cf64a9e8e does not set *reply to
NULL when its internal mpath_send_cmd() call fails, so I think Kevin's
interpretation is correct.

As it stands, there is no observable bug in the QEMU code though because
reply is initialized to NULL before calling multipath_process_cmd().
This patch is just a cleanup.

Cc: Benjamin Marzinski <bmarzins@redhat.com>
Cc: kwolf@redhat.com
Cc: eblake@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
Eric pointed out that g_autofree could eliminate the manual free(3)
calls. In this case we cannot use it since g_autofree calls glib's
g_free() rather than the standard library's free(3).
---
 scsi/qemu-pr-helper.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index 54d196a503f..d52109cab25 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -571,13 +571,17 @@ static bool multipathd_cmd(int fd, const char *cmd, Error **errp)
         free(reply);
         return false;
     }
-    free(reply);
     if (ret == -1) {
+        /*
+         * reply is not freed because the documentation only defines it when
+         * the function returns success.
+         */
         error_setg_errno(errp, last_errno,
                          "mpath_process_cmd(%d, \"%s\") failed",
                          fd, cmd);
         return false;
     }
+    free(reply);
     return true;
 }
 
-- 
2.56.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-19 20:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 15:33 [PATCH] qemu-pr-helper: do not free reply when multipath_process_cmd() fails Stefan Hajnoczi
2026-10-19 16:19 ` Eric Blake
2026-10-19 20:57   ` Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.