mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
vbox: snapshot: Avoid memleak in virVBoxSnapshotConfAllChildren
On re-allocation failure the function would leak already allocated memory.
This commit is contained in:
parent
810eea719c
commit
ca9a94a0a9
@ -477,24 +477,32 @@ virVBoxSnapshotConfAllChildren(virVBoxSnapshotConfHardDiskPtr disk,
|
|||||||
virVBoxSnapshotConfHardDiskPtr *tempList = NULL;
|
virVBoxSnapshotConfHardDiskPtr *tempList = NULL;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(ret, 0) < 0)
|
if (VIR_ALLOC_N(ret, 0) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < disk->nchildren; i++) {
|
for (i = 0; i < disk->nchildren; i++) {
|
||||||
tempSize = virVBoxSnapshotConfAllChildren(disk->children[i], &tempList);
|
tempSize = virVBoxSnapshotConfAllChildren(disk->children[i], &tempList);
|
||||||
if (VIR_EXPAND_N(ret, returnSize, tempSize) < 0)
|
if (VIR_EXPAND_N(ret, returnSize, tempSize) < 0)
|
||||||
return 0;
|
goto error;
|
||||||
|
|
||||||
for (j = 0; j < tempSize; j++) {
|
for (j = 0; j < tempSize; j++)
|
||||||
ret[returnSize - tempSize + j] = tempList[j];
|
ret[returnSize - tempSize + j] = tempList[j];
|
||||||
}
|
|
||||||
|
VIR_FREE(tempList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_EXPAND_N(ret, returnSize, 1) < 0)
|
if (VIR_EXPAND_N(ret, returnSize, 1) < 0)
|
||||||
return 0;
|
goto error;
|
||||||
|
|
||||||
ret[returnSize - 1] = disk;
|
ret[returnSize - 1] = disk;
|
||||||
*list = ret;
|
*list = ret;
|
||||||
return returnSize;
|
return returnSize;
|
||||||
|
|
||||||
|
error:
|
||||||
|
VIR_FREE(tempList);
|
||||||
|
VIR_FREE(ret);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user