[libvirt] [PATCH 04/18] cpu: Use a different name for the copy in ppc64ModelFromCPU()

Andrea Bolognani abologna at redhat.com
Tue Aug 4 09:37:55 UTC 2015


While the previous code was correct, it looked wrong at first
sight because the same variable used to store the result of a
map lookup is later used to store a copy of said result. The
copy is deallocated on error, but due to the fact that a single
variable is used, it looks like the result of the lookup is
deallocated instead, which would be a bug.

Using a separate variable for the copy means the code is just
as correct but much less likely to result confusing.

No functional changes.
---
 src/cpu/cpu_ppc64.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index dd02a3f..c769221 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -162,6 +162,7 @@ ppc64ModelFromCPU(const virCPUDef *cpu,
                   const struct ppc64_map *map)
 {
     struct ppc64_model *model;
+    struct ppc64_model *copy;
 
     if (!(model = ppc64ModelFind(map, cpu->model))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -169,13 +170,13 @@ ppc64ModelFromCPU(const virCPUDef *cpu,
         goto error;
     }
 
-    if (!(model = ppc64ModelCopy(model)))
+    if (!(copy = ppc64ModelCopy(model)))
         goto error;
 
-    return model;
+    return copy;
 
  error:
-    ppc64ModelFree(model);
+    ppc64ModelFree(copy);
     return NULL;
 }
 
-- 
2.4.3




More information about the libvir-list mailing list