提交 ede91bde 编写于 作者: J John Ferlan

storage: Resolve resource leaks with cmd processing

上级 1c8c8190
/*
* storage_backend_disk.c: storage backend for disk handling
*
* Copyright (C) 2007-2008, 2010-2012 Red Hat, Inc.
* Copyright (C) 2007-2008, 2010-2013 Red Hat, Inc.
* Copyright (C) 2007-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
......@@ -385,14 +385,7 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
{
bool ok_to_mklabel = false;
int ret = -1;
/* eg parted /dev/sda mklabel msdos */
virCommandPtr cmd = virCommandNewArgList(PARTED,
pool->def->source.devices[0].path,
"mklabel",
"--script",
((pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) ? "msdos" :
virStoragePoolFormatDiskTypeToString(pool->def->source.format)),
NULL);
virCommandPtr cmd = NULL;
virCheckFlags(VIR_STORAGE_POOL_BUILD_OVERWRITE |
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret);
......@@ -423,8 +416,17 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
}
}
if (ok_to_mklabel)
if (ok_to_mklabel) {
/* eg parted /dev/sda mklabel msdos */
cmd = virCommandNewArgList(PARTED,
pool->def->source.devices[0].path,
"mklabel",
"--script",
((pool->def->source.format == VIR_STORAGE_POOL_DISK_DOS) ? "msdos" :
virStoragePoolFormatDiskTypeToString(pool->def->source.format)),
NULL);
ret = virCommandRun(cmd, NULL);
}
error:
virCommandFree(cmd);
......@@ -634,7 +636,7 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStorageVolDefPtr vol)
{
int res = -1;
char *partFormat;
char *partFormat = NULL;
unsigned long long startOffset = 0, endOffset = 0;
virCommandPtr cmd = virCommandNewArgList(PARTED,
pool->def->source.devices[0].path,
......@@ -646,11 +648,11 @@ virStorageBackendDiskCreateVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("storage pool does not support encrypted "
"volumes"));
return -1;
goto cleanup;
}
if (virStorageBackendDiskPartFormat(pool, vol, &partFormat) != 0) {
return -1;
goto cleanup;
}
virCommandAddArg(cmd, partFormat);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册