storage: Add error path for virStorageBackendCreateQemuImgCmdFromVol

Rather than inline the various free's and return NULL, just create
an error label.
This commit is contained in:
John Ferlan 2017-10-06 12:12:38 -04:00
parent ae94084b76
commit 07731f9917

View File

@ -1261,19 +1261,13 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
if (info.format == VIR_STORAGE_FILE_RAW && if (info.format == VIR_STORAGE_FILE_RAW &&
vol->target.encryption != NULL && vol->target.encryption != NULL &&
vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
if (storageBackendCreateQemuImgSecretObject(cmd, vol, &info) < 0) { if (storageBackendCreateQemuImgSecretObject(cmd, vol, &info) < 0)
VIR_FREE(info.secretAlias); goto error;
virCommandFree(cmd);
return NULL;
}
enc = &vol->target.encryption->encinfo; enc = &vol->target.encryption->encinfo;
} }
if (storageBackendCreateQemuImgSetOptions(cmd, imgformat, enc, info) < 0) { if (storageBackendCreateQemuImgSetOptions(cmd, imgformat, enc, info) < 0)
VIR_FREE(info.secretAlias); goto error;
virCommandFree(cmd);
return NULL;
}
VIR_FREE(info.secretAlias); VIR_FREE(info.secretAlias);
if (info.inputPath) if (info.inputPath)
@ -1283,6 +1277,11 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
virCommandAddArgFormat(cmd, "%lluK", info.size_arg); virCommandAddArgFormat(cmd, "%lluK", info.size_arg);
return cmd; return cmd;
error:
VIR_FREE(info.secretAlias);
virCommandFree(cmd);
return NULL;
} }