[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 1/2] virCommand: document behavior on no output



Option 1: This patch (all callers have to worry about NULL buffers,
but checking for output is a simple pointer check).

Option 2: Guarantee that outbuf/errbuf are allocated, even if to
the empty string.  Caller always has to free the result, and
empty output check requires checking if *outbuf=='\0'.

Personally, I prefer option 2.  Thoughts?

* docs/internals/command.html.in: Update documentation.
* src/util/command.c (virCommandSetOutputBuffer)
(virCommandSetErrorBuffer) Guarantee NULL buffer on no output.
---
 docs/internals/command.html.in |    4 ++--
 src/util/command.c             |    2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/docs/internals/command.html.in b/docs/internals/command.html.in
index c4fa800..ea9ec64 100644
--- a/docs/internals/command.html.in
+++ b/docs/internals/command.html.in
@@ -349,8 +349,8 @@

     <p>
       Once the command has finished executing, these buffers
-      will contain the output. It is the callers responsibility
-      to free these buffers.
+      will contain the output, or be NULL if there was no output. It
+      is the callers responsibility to free these buffers.
     </p>

     <h3><a name="directory">Setting working directory</a></h3>
diff --git a/src/util/command.c b/src/util/command.c
index aa43f76..1923799 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -549,6 +549,7 @@ virCommandSetOutputBuffer(virCommandPtr cmd, char **outbuf)
         return;
     }

+    VIR_FREE(*outbuf);
     cmd->outbuf = outbuf;
     cmd->outfdptr = &cmd->outfd;
 }
@@ -569,6 +570,7 @@ virCommandSetErrorBuffer(virCommandPtr cmd, char **errbuf)
         return;
     }

+    VIR_FREE(*errbuf);
     cmd->errbuf = errbuf;
     cmd->errfdptr = &cmd->errfd;
 }
-- 
1.7.3.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]