On Tue, Aug 04, 2015 at 11:37:55 +0200, Andrea Bolognani wrote:
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;
You forgot to initialize copy to NULL, but why not just
return ppc64ModelCopy(model);
and removing "copy" end the error label completely since it will never
do anything anyway?
Jirka