[PATCH 4/9] virCommandSetSendBuffer: Take double pointer of @buffer

Michal Privoznik mprivozn at redhat.com
Wed Nov 30 09:48:06 UTC 2022


The virCommandSetSendBuffer() function consumes passed @buffer,
but takes it only as plain pointer. Switch to a double pointer to
make this obvious. This allows us then to drop all
g_steal_pointer() in callers.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/qemu/qemu_tpm.c   | 2 +-
 src/util/vircommand.c | 6 +++---
 src/util/vircommand.h | 2 +-
 tests/commandtest.c   | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index bdce060db8..d2f5bfb055 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -265,7 +265,7 @@ qemuTPMSetupEncryption(const unsigned char *secretuuid,
                                  &secret, &secret_len) < 0)
         return -1;
 
-    *fd = virCommandSetSendBuffer(cmd, g_steal_pointer(&secret), secret_len);
+    *fd = virCommandSetSendBuffer(cmd, &secret, secret_len);
     return 0;
 }
 
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 4f60432c0a..0917bc9cfb 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -1699,10 +1699,10 @@ virCommandFreeSendBuffers(virCommand *cmd)
  */
 int
 virCommandSetSendBuffer(virCommand *cmd,
-                        unsigned char *buffer,
+                        unsigned char **buffer,
                         size_t buflen)
 {
-    g_autofree unsigned char *localbuf = g_steal_pointer(&buffer);
+    g_autofree unsigned char *localbuf = g_steal_pointer(buffer);
     int pipefd[2] = { -1, -1 };
     size_t i;
 
@@ -2901,7 +2901,7 @@ int virCommandHandshakeNotify(virCommand *cmd)
 #else /* WIN32 */
 int
 virCommandSetSendBuffer(virCommand *cmd,
-                        unsigned char *buffer G_GNUC_UNUSED,
+                        unsigned char **buffer G_GNUC_UNUSED,
                         size_t buflen G_GNUC_UNUSED)
 {
     if (virCommandHasError(cmd))
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index 98788bcbf7..e0002103b6 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -132,7 +132,7 @@ void virCommandSetWorkingDirectory(virCommand *cmd,
                                    const char *pwd) ATTRIBUTE_NONNULL(2);
 
 int virCommandSetSendBuffer(virCommand *cmd,
-                            unsigned char *buffer,
+                            unsigned char **buffer,
                             size_t buflen)
     ATTRIBUTE_NONNULL(2);
 
diff --git a/tests/commandtest.c b/tests/commandtest.c
index 9bbf6fb260..8c5a9245a1 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -1075,8 +1075,8 @@ static int test27(const void *unused G_GNUC_UNUSED)
     errexpect = g_strdup_printf(TEST27_ERREXPECT_TEMP,
                                 buffer0, buffer1, buffer2);
 
-    buf1fd = virCommandSetSendBuffer(cmd, g_steal_pointer(&buffer1), buflen - 1);
-    buf2fd = virCommandSetSendBuffer(cmd, g_steal_pointer(&buffer2), buflen - 1);
+    buf1fd = virCommandSetSendBuffer(cmd, &buffer1, buflen - 1);
+    buf2fd = virCommandSetSendBuffer(cmd, &buffer2, buflen - 1);
 
     virCommandAddArg(cmd, "--readfd");
     virCommandAddArgFormat(cmd, "%d", buf1fd);
-- 
2.37.4



More information about the libvir-list mailing list