提交 63ee3b66 编写于 作者: M Michal Privoznik

Adapt to VIR_STRDUP and VIR_STRNDUP in src/xenapi/*

上级 5162a076
...@@ -135,12 +135,8 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, ...@@ -135,12 +135,8 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
} }
if (conn->uri->user != NULL) { if (conn->uri->user != NULL) {
username = strdup(conn->uri->user); if (VIR_STRDUP(username, conn->uri->user) < 0)
if (username == NULL) {
virReportOOMError();
goto error; goto error;
}
} else { } else {
username = virAuthGetUsername(conn, auth, "xen", NULL, conn->uri->server); username = virAuthGetUsername(conn, auth, "xen", NULL, conn->uri->server);
...@@ -320,9 +316,8 @@ xenapiConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) ...@@ -320,9 +316,8 @@ xenapiConnectGetVersion(virConnectPtr conn, unsigned long *hvVer)
if (result && result->size > 0) { if (result && result->size > 0) {
for (i = 0; i < result->size; i++) { for (i = 0; i < result->size; i++) {
if (STREQ(result->contents[i].key, "xen")) { if (STREQ(result->contents[i].key, "xen")) {
if (!(version = strdup(result->contents[i].val))) { if (VIR_STRDUP(version, result->contents[i].val) < 0) {
xen_string_string_map_free(result); xen_string_string_map_free(result);
virReportOOMError();
return -1; return -1;
} }
break; break;
...@@ -952,8 +947,8 @@ xenapiDomainGetOSType(virDomainPtr dom) ...@@ -952,8 +947,8 @@ xenapiDomainGetOSType(virDomainPtr dom)
xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR, NULL); xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR, NULL);
goto cleanup; goto cleanup;
} }
if (!(ostype = (STREQ(boot_policy,"BIOS order") ? strdup("hvm") : strdup("xen")))) ignore_value(VIR_STRDUP(ostype,
virReportOOMError(); STREQ(boot_policy, "BIOS order") ? "hvm" : "xen"));
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
} else } else
xenapiSessionErrorHandler(dom->conn, VIR_ERR_NO_DOMAIN, NULL); xenapiSessionErrorHandler(dom->conn, VIR_ERR_NO_DOMAIN, NULL);
...@@ -1268,10 +1263,9 @@ xenapiDomainGetVcpus(virDomainPtr dom, ...@@ -1268,10 +1263,9 @@ xenapiDomainGetVcpus(virDomainPtr dom,
} }
for (i = 0; i < vcpu_params->size; i++) { for (i = 0; i < vcpu_params->size; i++) {
if (STREQ(vcpu_params->contents[i].key, "mask")) { if (STREQ(vcpu_params->contents[i].key, "mask")) {
if (!(mask = strdup(vcpu_params->contents[i].val))){ if (VIR_STRDUP(mask, vcpu_params->contents[i].val) < 0) {
xen_vm_set_free(vms); xen_vm_set_free(vms);
xen_string_string_map_free(vcpu_params); xen_string_string_map_free(vcpu_params);
virReportOOMError();
return -1; return -1;
} }
break; break;
...@@ -1386,13 +1380,13 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) ...@@ -1386,13 +1380,13 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
defPtr->virtType = VIR_DOMAIN_VIRT_XEN; defPtr->virtType = VIR_DOMAIN_VIRT_XEN;
defPtr->id = dom->id; defPtr->id = dom->id;
memcpy(defPtr->uuid, dom->uuid, VIR_UUID_BUFLEN); memcpy(defPtr->uuid, dom->uuid, VIR_UUID_BUFLEN);
if (!(defPtr->name = strdup(dom->name))) if (VIR_STRDUP(defPtr->name, dom->name) < 0)
goto error_cleanup; goto error;
xen_vm_get_hvm_boot_policy(session, &boot_policy, vm); xen_vm_get_hvm_boot_policy(session, &boot_policy, vm);
if (STREQ(boot_policy,"BIOS order")) { if (STREQ(boot_policy,"BIOS order")) {
if (!(defPtr->os.type = strdup("hvm"))) { if (VIR_STRDUP(defPtr->os.type, "hvm") < 0) {
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
goto error_cleanup; goto error;
} }
xen_vm_get_hvm_boot_params(session, &result, vm); xen_vm_get_hvm_boot_params(session, &result, vm);
if (result != NULL) { if (result != NULL) {
...@@ -1413,50 +1407,50 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) ...@@ -1413,50 +1407,50 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
} else { } else {
char *value = NULL; char *value = NULL;
if (!(defPtr->os.type = strdup("xen"))) { if (VIR_STRDUP(defPtr->os.type, "xen") < 0) {
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
goto error_cleanup; goto error;
} }
if (!(defPtr->os.loader = strdup("pygrub"))) { if (VIR_STRDUP(defPtr->os.loader, "pygrub") < 0) {
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
goto error_cleanup; goto error;
} }
xen_vm_get_pv_kernel(session, &value, vm); xen_vm_get_pv_kernel(session, &value, vm);
if (STRNEQ(value, "")) { if (STRNEQ(value, "")) {
if (!(defPtr->os.kernel = strdup(value))) { if (VIR_STRDUP(defPtr->os.kernel, value) < 0) {
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
VIR_FREE(value); VIR_FREE(value);
goto error_cleanup; goto error;
} }
VIR_FREE(value); VIR_FREE(value);
} }
xen_vm_get_pv_ramdisk(session, &value, vm); xen_vm_get_pv_ramdisk(session, &value, vm);
if (STRNEQ(value, "")) { if (STRNEQ(value, "")) {
if (!(defPtr->os.initrd = strdup(value))) { if (VIR_STRDUP(defPtr->os.initrd, value) < 0) {
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
VIR_FREE(value); VIR_FREE(value);
goto error_cleanup; goto error;
} }
VIR_FREE(value); VIR_FREE(value);
} }
xen_vm_get_pv_args(session, &value, vm); xen_vm_get_pv_args(session, &value, vm);
if (STRNEQ(value, "")) { if (STRNEQ(value, "")) {
if (!(defPtr->os.cmdline = strdup(value))) { if (VIR_STRDUP(defPtr->os.cmdline, value) < 0) {
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
VIR_FREE(value); VIR_FREE(value);
goto error_cleanup; goto error;
} }
VIR_FREE(value); VIR_FREE(value);
} }
VIR_FREE(boot_policy); VIR_FREE(boot_policy);
if (!(defPtr->os.bootloader = strdup("pygrub"))) if (VIR_STRDUP(defPtr->os.bootloader, "pygrub") < 0)
goto error_cleanup; goto error;
} }
xen_vm_get_pv_bootloader_args(session, &val, vm); xen_vm_get_pv_bootloader_args(session, &val, vm);
if (STRNEQ(val, "")) { if (STRNEQ(val, "")) {
if (!(defPtr->os.bootloaderArgs = strdup(val))) { if (VIR_STRDUP(defPtr->os.bootloaderArgs, val) < 0) {
VIR_FREE(val); VIR_FREE(val);
goto error_cleanup; goto error;
} }
VIR_FREE(val); VIR_FREE(val);
} }
...@@ -1542,6 +1536,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) ...@@ -1542,6 +1536,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
error_cleanup: error_cleanup:
virReportOOMError(); virReportOOMError();
error:
xen_vm_set_free(vms); xen_vm_set_free(vms);
virDomainDefFree(defPtr); virDomainDefFree(defPtr);
return NULL; return NULL;
...@@ -1569,8 +1564,7 @@ xenapiConnectListDefinedDomains(virConnectPtr conn, char **const names, ...@@ -1569,8 +1564,7 @@ xenapiConnectListDefinedDomains(virConnectPtr conn, char **const names,
if (record != NULL) { if (record != NULL) {
if (record->is_a_template == 0) { if (record->is_a_template == 0) {
char *usenames = NULL; char *usenames = NULL;
if (!(usenames = strdup(record->name_label))) { if (VIR_STRDUP(usenames, record->name_label) < 0) {
virReportOOMError();
xen_vm_record_free(record); xen_vm_record_free(record);
xen_vm_set_free(result); xen_vm_set_free(result);
while (--j >= 0) VIR_FREE(names[j]); while (--j >= 0) VIR_FREE(names[j]);
...@@ -1862,8 +1856,7 @@ xenapiDomainGetSchedulerType(virDomainPtr dom ATTRIBUTE_UNUSED, int *nparams) ...@@ -1862,8 +1856,7 @@ xenapiDomainGetSchedulerType(virDomainPtr dom ATTRIBUTE_UNUSED, int *nparams)
if (nparams) if (nparams)
*nparams = 0; *nparams = 0;
if (!(result = strdup("credit"))) ignore_value(VIR_STRDUP(result, "credit"));
virReportOOMError();
return result; return result;
} }
......
...@@ -352,12 +352,12 @@ allocStringMap(xen_string_string_map **strings, char *key, char *val) ...@@ -352,12 +352,12 @@ allocStringMap(xen_string_string_map **strings, char *key, char *val)
return -1; return -1;
} }
(*strings)->size = sz; (*strings)->size = sz;
if (!((*strings)->contents[sz-1].key = strdup(key))) goto error; if (VIR_STRDUP((*strings)->contents[sz-1].key, key) < 0 ||
if (!((*strings)->contents[sz-1].val = strdup(val))) goto error; VIR_STRDUP((*strings)->contents[sz-1].val, val) < 0)
goto error;
return 0; return 0;
error: error:
xen_string_string_map_free(*strings); xen_string_string_map_free(*strings);
virReportOOMError();
return -1; return -1;
} }
...@@ -455,17 +455,17 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def, ...@@ -455,17 +455,17 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
int i; int i;
*record = xen_vm_record_alloc(); *record = xen_vm_record_alloc();
if (!((*record)->name_label = strdup(def->name))) if (VIR_STRDUP((*record)->name_label, def->name) < 0)
goto error_cleanup; goto error;
if (def->uuid) { if (def->uuid) {
virUUIDFormat(def->uuid, uuidStr); virUUIDFormat(def->uuid, uuidStr);
if (!((*record)->uuid = strdup(uuidStr))) if (VIR_STRDUP((*record)->uuid, uuidStr) < 0)
goto error_cleanup; goto error;
} }
if (STREQ(def->os.type, "hvm")) { if (STREQ(def->os.type, "hvm")) {
char *boot_order = NULL; char *boot_order = NULL;
if (!((*record)->hvm_boot_policy = strdup("BIOS order"))) if (VIR_STRDUP((*record)->hvm_boot_policy, "BIOS order") < 0)
goto error_cleanup; goto error;
if (def->os.nBootDevs != 0) if (def->os.nBootDevs != 0)
boot_order = createXenAPIBootOrderString(def->os.nBootDevs, &def->os.bootDevs[0]); boot_order = createXenAPIBootOrderString(def->os.nBootDevs, &def->os.bootDevs[0]);
if (boot_order != NULL) { if (boot_order != NULL) {
...@@ -475,25 +475,25 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def, ...@@ -475,25 +475,25 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
VIR_FREE(boot_order); VIR_FREE(boot_order);
} }
} else if (STREQ(def->os.type, "xen")) { } else if (STREQ(def->os.type, "xen")) {
if (!((*record)->pv_bootloader = strdup("pygrub"))) if (VIR_STRDUP((*record)->pv_bootloader, "pygrub") < 0)
goto error_cleanup; goto error;
if (def->os.kernel) { if (def->os.kernel) {
if (!((*record)->pv_kernel = strdup(def->os.kernel))) if (VIR_STRDUP((*record)->pv_kernel, def->os.kernel) < 0)
goto error_cleanup; goto error;
} }
if (def->os.initrd) { if (def->os.initrd) {
if (!((*record)->pv_ramdisk = strdup(def->os.initrd))) if (VIR_STRDUP((*record)->pv_ramdisk, def->os.initrd) < 0)
goto error_cleanup; goto error;
} }
if (def->os.cmdline) { if (def->os.cmdline) {
if (!((*record)->pv_args = strdup(def->os.cmdline))) if (VIR_STRDUP((*record)->pv_args, def->os.cmdline) < 0)
goto error_cleanup; goto error;
} }
(*record)->hvm_boot_params = xen_string_string_map_alloc(0); (*record)->hvm_boot_params = xen_string_string_map_alloc(0);
} }
if (def->os.bootloaderArgs) if (def->os.bootloaderArgs)
if (!((*record)->pv_bootloader_args = strdup(def->os.bootloaderArgs))) if (VIR_STRDUP((*record)->pv_bootloader_args, def->os.bootloaderArgs) < 0)
goto error_cleanup; goto error;
if (def->mem.cur_balloon) if (def->mem.cur_balloon)
(*record)->memory_static_max = (int64_t) (def->mem.cur_balloon * 1024); (*record)->memory_static_max = (int64_t) (def->mem.cur_balloon * 1024);
...@@ -561,6 +561,7 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def, ...@@ -561,6 +561,7 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
error_cleanup: error_cleanup:
virReportOOMError(); virReportOOMError();
error:
xen_vm_record_free(*record); xen_vm_record_free(*record);
return -1; return -1;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册