[libvirt] [PATCH 2/2] virTypedParamsDeserialize: minor fixes

Marc Hartmayer mhartmay at linux.vnet.ibm.com
Wed Apr 25 15:55:38 UTC 2018


1. Don't allocate if there is nothing that needs to be
   allocated. Especially as the result of calling calloc(0, ...) is
   implementation-defined.
2. Reset @nparams to 0 in case of an error.

Signed-off-by: Marc Hartmayer <mhartmay at linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
---
 src/util/virtypedparam.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index 10fd28baa65c..01716b517ad2 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -1402,7 +1402,7 @@ virTypedParamsDeserialize(virTypedParameterRemotePtr remote_params,
             goto cleanup;
         }
     } else {
-        if (VIR_ALLOC_N(*params, remote_params_len) < 0)
+        if (remote_params_len && VIR_ALLOC_N(*params, remote_params_len) < 0)
             goto cleanup;
     }
     *nparams = remote_params_len;
@@ -1467,6 +1467,7 @@ virTypedParamsDeserialize(virTypedParameterRemotePtr remote_params,
         } else {
             virTypedParamsFree(*params, i);
             *params = NULL;
+            *nparams = 0;
         }
     }
     return rv;
-- 
2.13.4




More information about the libvir-list mailing list