[Libguestfs] [PATCH 3/4] common/qemuopts: use the old pointer as realloc pointer

Pino Toscano ptoscano at redhat.com
Mon Apr 30 11:07:52 UTC 2018


Call realloc() directly with the pointer to the old data, instead of
assigning it to the destination variable, and using that one.  The rest
of the code is the same, already properly checking for the results of
realloc(), so this mostly help static code analyzers.
---
 common/qemuopts/qemuopts.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/common/qemuopts/qemuopts.c b/common/qemuopts/qemuopts.c
index c40d44783..b3e69e306 100644
--- a/common/qemuopts/qemuopts.c
+++ b/common/qemuopts/qemuopts.c
@@ -168,8 +168,7 @@ extend_options (struct qemuopts *qopts)
       qopts->nr_alloc = 1;
     else
       qopts->nr_alloc *= 2;
-    new_options = qopts->options;
-    new_options = realloc (new_options,
+    new_options = realloc (qopts->options,
                            qopts->nr_alloc * sizeof (struct qopt));
     if (new_options == NULL)
       return NULL;
@@ -421,8 +420,7 @@ qemuopts_append_arg_list (struct qemuopts *qopts, const char *value)
   if (value_copy == NULL)
     return -1;
 
-  new_values = qopt->values;
-  new_values = realloc (new_values, (len+2) * sizeof (char *));
+  new_values = realloc (qopt->values, (len+2) * sizeof (char *));
   if (new_values == NULL) {
     free (value_copy);
     return -1;
-- 
2.14.3




More information about the Libguestfs mailing list