Use virBufferCheckError everywhere we report OOM error

Replace:
if (virBufferError(&buf)) {
    virBufferFreeAndReset(&buf);
    virReportOOMError();
    ...
}

with:
if (virBufferCheckError(&buf) < 0)
    ...

This should not be a functional change (unless some callers
misused the virBuffer APIs - a different error would be reported
then)
This commit is contained in:
Ján Tomko 2014-06-27 10:40:15 +02:00
parent 28b9be2481
commit 92a8e72f9d
51 changed files with 158 additions and 456 deletions

View File

@ -258,10 +258,8 @@ bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
if (virSysinfoFormat(&buf, privconn->hostsysinfo) < 0) if (virSysinfoFormat(&buf, privconn->hostsysinfo) < 0)
return NULL; return NULL;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
@ -701,10 +699,8 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
virBufferAddChar(&buf, '\n'); virBufferAddChar(&buf, '\n');
virBufferAdd(&buf, virCommandToString(cmd), -1); virBufferAdd(&buf, virCommandToString(cmd), -1);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
ret = virBufferContentAndReset(&buf); ret = virBufferContentAndReset(&buf);

View File

@ -494,13 +494,11 @@ virCPUDefFormat(virCPUDefPtr def,
if (virCPUDefFormatBufFull(&buf, def, flags) < 0) if (virCPUDefFormatBufFull(&buf, def, flags) < 0)
goto cleanup; goto cleanup;
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto cleanup;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
cleanup: cleanup:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;

View File

@ -11335,11 +11335,8 @@ virDomainDefParseXML(xmlDocPtr xml,
} }
} }
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
virBufferFreeAndReset(&buffer);
goto error; goto error;
}
string = virBufferContentAndReset(&buffer); string = virBufferContentAndReset(&buffer);
@ -17972,13 +17969,11 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virBufferAdjustIndent(buf, -2); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</domain>\n"); virBufferAddLit(buf, "</domain>\n");
if (virBufferError(buf)) if (virBufferCheckError(buf) < 0)
goto no_memory; goto error;
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virBufferFreeAndReset(buf); virBufferFreeAndReset(buf);
return -1; return -1;
@ -18030,13 +18025,11 @@ virDomainObjFormat(virDomainXMLOptionPtr xmlopt,
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</domstatus>\n"); virBufferAddLit(&buf, "</domstatus>\n");
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto error;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
error: error:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;

View File

@ -1101,11 +1101,11 @@ virInterfaceDefDevFormat(virBufferPtr buf, const virInterfaceDef *def,
virBufferAdjustIndent(buf, -2); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</interface>\n"); virBufferAddLit(buf, "</interface>\n");
if (virBufferError(buf)) if (virBufferCheckError(buf) < 0)
goto no_memory; goto cleanup;
return 0; return 0;
no_memory:
virReportOOMError();
cleanup: cleanup:
return -1; return -1;
} }

View File

@ -2830,13 +2830,11 @@ virNetworkDefFormat(const virNetworkDef *def,
if (virNetworkDefFormatBuf(&buf, def, flags) < 0) if (virNetworkDefFormatBuf(&buf, def, flags) < 0)
goto error; goto error;
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto error;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
error: error:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;
@ -2871,13 +2869,11 @@ virNetworkObjFormat(virNetworkObjPtr net,
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</networkstatus>"); virBufferAddLit(&buf, "</networkstatus>");
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto error;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
error: error:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;

View File

@ -555,15 +555,10 @@ char *virNodeDeviceDefFormat(const virNodeDeviceDef *def)
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</device>\n"); virBufferAddLit(&buf, "</device>\n");
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; return NULL;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
virBufferFreeAndReset(&buf);
return NULL;
} }
/** /**

View File

@ -967,10 +967,8 @@ virNWFilterPrintTCPFlags(uint8_t flags)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
printTCPFlags(&buf, flags); printTCPFlags(&buf, flags);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
@ -2548,11 +2546,8 @@ virNWFilterIsAllowedChain(const char *chainname)
printed = true; printed = true;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
virBufferFreeAndReset(&buf);
goto err_exit; goto err_exit;
}
msg = virBufferContentAndReset(&buf); msg = virBufferContentAndReset(&buf);
@ -3484,14 +3479,11 @@ virNWFilterDefFormat(const virNWFilterDef *def)
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</filter>\n"); virBufferAddLit(&buf, "</filter>\n");
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto err_exit;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
err_exit: err_exit:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;

View File

@ -318,13 +318,11 @@ virSecretDefFormat(const virSecretDef *def)
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</secret>\n"); virBufferAddLit(&buf, "</secret>\n");
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto error;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
error: error:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;

View File

@ -705,11 +705,8 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</domainsnapshot>\n"); virBufferAddLit(&buf, "</domainsnapshot>\n");
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -1239,13 +1239,11 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def)
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</pool>\n"); virBufferAddLit(&buf, "</pool>\n");
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto cleanup;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
cleanup: cleanup:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;
@ -1662,13 +1660,11 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</volume>\n"); virBufferAddLit(&buf, "</volume>\n");
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto cleanup;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
cleanup: cleanup:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;
@ -2013,13 +2009,11 @@ virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def)
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</sources>\n"); virBufferAddLit(&buf, "</sources>\n");
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto cleanup;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory:
virReportOOMError();
cleanup: cleanup:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;

View File

@ -112,12 +112,14 @@ int cpuMapLoad(const char *arch,
goto cleanup; goto cleanup;
} }
if ((ctxt = xmlXPathNewContext(xml)) == NULL) if ((ctxt = xmlXPathNewContext(xml)) == NULL) {
goto no_memory; virReportOOMError();
goto cleanup;
}
virBufferAsprintf(&buf, "./arch[@name='%s']", arch); virBufferAsprintf(&buf, "./arch[@name='%s']", arch);
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto cleanup;
xpath = virBufferContentAndReset(&buf); xpath = virBufferContentAndReset(&buf);
@ -146,8 +148,4 @@ int cpuMapLoad(const char *arch,
VIR_FREE(mapfile); VIR_FREE(mapfile);
return ret; return ret;
no_memory:
virReportOOMError();
goto cleanup;
} }

View File

@ -1221,11 +1221,8 @@ x86CPUDataFormat(const virCPUData *data)
} }
virBufferAddLit(&buf, "</cpudata>\n"); virBufferAddLit(&buf, "</cpudata>\n");
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -340,10 +340,8 @@ esxFormatVMXFileName(const char *fileName, void *opaque)
virBufferAddChar(&buffer, separator); virBufferAddChar(&buffer, separator);
virBufferAdd(&buffer, directoryAndFileName, -1); virBufferAdd(&buffer, directoryAndFileName, -1);
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
result = virBufferContentAndReset(&buffer); result = virBufferContentAndReset(&buffer);
} else if (*fileName == '/') { } else if (*fileName == '/') {
@ -2701,10 +2699,8 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
virBufferAddLit(&buffer, "&dsName="); virBufferAddLit(&buffer, "&dsName=");
virBufferURIEncodeString(&buffer, datastoreName); virBufferURIEncodeString(&buffer, datastoreName);
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
url = virBufferContentAndReset(&buffer); url = virBufferContentAndReset(&buffer);
@ -3169,10 +3165,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
virBufferAddLit(&buffer, "&dsName="); virBufferAddLit(&buffer, "&dsName=");
virBufferURIEncodeString(&buffer, datastoreName); virBufferURIEncodeString(&buffer, datastoreName);
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
url = virBufferContentAndReset(&buffer); url = virBufferContentAndReset(&buffer);

View File

@ -425,12 +425,8 @@ esxUtil_EscapeBase64(const char *string)
} }
} }
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
virBufferFreeAndReset(&buffer);
return NULL; return NULL;
}
return virBufferContentAndReset(&buffer); return virBufferContentAndReset(&buffer);
} }
@ -498,12 +494,8 @@ esxUtil_EscapeForXml(const char *string)
virBufferEscapeString(&buffer, "%s", string); virBufferEscapeString(&buffer, "%s", string);
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
virBufferFreeAndReset(&buffer);
return NULL; return NULL;
}
return virBufferContentAndReset(&buffer); return virBufferContentAndReset(&buffer);
} }

View File

@ -426,10 +426,8 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content,
goto cleanup; goto cleanup;
} }
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (length) { if (length) {
*length = virBufferUse(&buffer); *length = virBufferUse(&buffer);
@ -1046,10 +1044,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
goto cleanup; goto cleanup;
} }
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
ctx->datacenterPath = virBufferContentAndReset(&buffer); ctx->datacenterPath = virBufferContentAndReset(&buffer);
@ -1116,10 +1112,8 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path)
goto cleanup; goto cleanup;
} }
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
ctx->computeResourcePath = virBufferContentAndReset(&buffer); ctx->computeResourcePath = virBufferContentAndReset(&buffer);
@ -1259,10 +1253,8 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName,
goto cleanup; goto cleanup;
} }
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
(*response)->content = virBufferContentAndReset(&buffer); (*response)->content = virBufferContentAndReset(&buffer);
@ -4243,10 +4235,8 @@ esxVI_HandleVirtualMachineQuestion
++answerIndex; ++answerIndex;
} }
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
possibleAnswers = virBufferContentAndReset(&buffer); possibleAnswers = virBufferContentAndReset(&buffer);
} }

View File

@ -126,10 +126,8 @@
virBufferAddLit(&buffer, "</"#_name">"); \ virBufferAddLit(&buffer, "</"#_name">"); \
virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER); \ virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER); \
\ \
if (virBufferError(&buffer)) { \ if (virBufferCheckError(&buffer) < 0) \
virReportOOMError(); \
goto cleanup; \ goto cleanup; \
} \
\ \
request = virBufferContentAndReset(&buffer); \ request = virBufferContentAndReset(&buffer); \
\ \

View File

@ -128,10 +128,8 @@ hypervEnumAndPull(hypervPrivate *priv, virBufferPtr query, const char *root,
return -1; return -1;
} }
if (virBufferError(query)) { if (virBufferCheckError(query) < 0)
virReportOOMError();
return -1; return -1;
}
serializerContext = wsmc_get_serialization_context(priv->client); serializerContext = wsmc_get_serialization_context(priv->client);

View File

@ -544,10 +544,8 @@ libxlConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0)
return NULL; return NULL;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -819,11 +819,8 @@ virLockManagerSanlockRegisterKillscript(int sock,
virBufferEscape(&buf, '\\', "\\ ", "%s", virBufferEscape(&buf, '\\', "\\ ", "%s",
virDomainLockFailureTypeToString(action)); virDomainLockFailureTypeToString(action));
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
goto cleanup; goto cleanup;
}
/* Unfortunately, sanlock_killpath() does not use const for either /* Unfortunately, sanlock_killpath() does not use const for either
* path or args even though it will just copy them into its own * path or args even though it will just copy them into its own

View File

@ -1181,8 +1181,8 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map,
virBufferAsprintf(&map_value, "%u %u %u\n", virBufferAsprintf(&map_value, "%u %u %u\n",
map[i].start, map[i].target, map[i].count); map[i].start, map[i].target, map[i].count);
if (virBufferError(&map_value)) if (virBufferCheckError(&map_value) < 0)
goto no_memory; goto cleanup;
VIR_DEBUG("Set '%s' to '%s'", path, virBufferCurrentContent(&map_value)); VIR_DEBUG("Set '%s' to '%s'", path, virBufferCurrentContent(&map_value));
@ -1195,10 +1195,6 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map,
cleanup: cleanup:
virBufferFreeAndReset(&map_value); virBufferFreeAndReset(&map_value);
return ret; return ret;
no_memory:
virReportOOMError();
goto cleanup;
} }
/** /**

View File

@ -2749,10 +2749,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].weight); vm->def->blkio.devices[j].weight);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -2778,10 +2776,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].riops); vm->def->blkio.devices[j].riops);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -2807,10 +2803,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].wiops); vm->def->blkio.devices[j].wiops);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -2836,10 +2830,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].rbps); vm->def->blkio.devices[j].rbps);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -2865,10 +2857,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].wbps); vm->def->blkio.devices[j].wbps);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -2913,10 +2903,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].weight); persistentDef->blkio.devices[j].weight);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -2947,10 +2935,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].riops); persistentDef->blkio.devices[j].riops);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -2980,10 +2966,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].wiops); persistentDef->blkio.devices[j].wiops);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -3013,10 +2997,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].rbps); persistentDef->blkio.devices[j].rbps);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -3047,10 +3029,8 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].wbps); persistentDef->blkio.devices[j].wbps);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -5374,10 +5354,8 @@ lxcConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0)
return NULL; return NULL;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -180,10 +180,10 @@ networkRunHook(virNetworkObjPtr network,
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</hookData>"); virBufferAddLit(&buf, "</hookData>");
if (virBufferError(&buf) || if (virBufferCheckError(&buf) < 0)
!(xml = virBufferContentAndReset(&buf)))
goto cleanup; goto cleanup;
xml = virBufferContentAndReset(&buf);
hookret = virHookCall(VIR_HOOK_DRIVER_NETWORK, network->def->name, hookret = virHookCall(VIR_HOOK_DRIVER_NETWORK, network->def->name,
op, sub_op, NULL, xml, NULL); op, sub_op, NULL, xml, NULL);
@ -1537,10 +1537,8 @@ networkRadvdConfContents(virNetworkObjPtr network, char **configstr)
virBufferAddLit(&configbuf, "};\n"); virBufferAddLit(&configbuf, "};\n");
if (virBufferError(&configbuf)) { if (virBufferCheckError(&configbuf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
*configstr = virBufferContentAndReset(&configbuf); *configstr = virBufferContentAndReset(&configbuf);

View File

@ -333,12 +333,8 @@ static int udevGenerateDeviceName(struct udev_device *device,
virBufferAsprintf(&buf, "_%s", s); virBufferAsprintf(&buf, "_%s", s);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf); return -1;
VIR_ERROR(_("Buffer error when generating device name for device "
"with sysname '%s'"), udev_device_get_sysname(device));
ret = -1;
}
def->name = virBufferContentAndReset(&buf); def->name = virBufferContentAndReset(&buf);

View File

@ -306,11 +306,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
} }
} }
if (virBufferError(&vb)) { if (virBufferCheckError(&vb) < 0)
virReportOOMError();
virBufferFreeAndReset(&vb);
return -1; return -1;
}
flags = virBufferContentAndReset(&vb); flags = virBufferContentAndReset(&vb);
@ -1560,11 +1557,8 @@ printStateMatchFlags(int32_t flags, char **bufptr)
"", "",
flags, flags,
false); false);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return -1; return -1;
}
*bufptr = virBufferContentAndReset(&buf); *bufptr = virBufferContentAndReset(&buf);
return 0; return 0;
} }

View File

@ -259,11 +259,8 @@ virNWFilterPrintVars(virHashTablePtr vars,
virHashForEach(vars, printString, &ps); virHashForEach(vars, printString, &ps);
if (virBufferError(&ps.buf)) { if (virBufferCheckError(&ps.buf) < 0)
virBufferFreeAndReset(&ps.buf);
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&ps.buf); return virBufferContentAndReset(&ps.buf);
} }

View File

@ -186,11 +186,8 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status,
channel = NULL; channel = NULL;
VIR_FREE(buffer); VIR_FREE(buffer);
if (virBufferError(&tex_ret)) { if (virBufferCheckError(&tex_ret) < 0)
virBufferFreeAndReset(&tex_ret);
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&tex_ret); return virBufferContentAndReset(&tex_ret);
err: err:
@ -211,11 +208,8 @@ phypExecBuffer(LIBSSH2_SESSION *session, virBufferPtr buf, int *exit_status,
char *cmd; char *cmd;
char *ret; char *ret;
if (virBufferError(buf)) { if (virBufferCheckError(buf) < 0)
virBufferFreeAndReset(buf);
virReportOOMError();
return NULL; return NULL;
}
cmd = virBufferContentAndReset(buf); cmd = virBufferContentAndReset(buf);
ret = phypExec(session, cmd, exit_status, conn); ret = phypExec(session, cmd, exit_status, conn);
VIR_FREE(cmd); VIR_FREE(cmd);

View File

@ -2962,10 +2962,8 @@ qemuBuildNetworkDriveURI(int protocol,
if (src) if (src)
virBufferAsprintf(&buf, ":exportname=%s", src); virBufferAsprintf(&buf, ":exportname=%s", src);
if (virBufferError(&buf) < 0) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
ret = virBufferContentAndReset(&buf); ret = virBufferContentAndReset(&buf);
goto cleanup; goto cleanup;
@ -3098,10 +3096,8 @@ qemuBuildNetworkDriveURI(int protocol,
} }
} }
if (virBufferError(&buf) < 0) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
ret = virBufferContentAndReset(&buf); ret = virBufferContentAndReset(&buf);
break; break;
@ -3557,10 +3553,8 @@ qemuBuildDriveStr(virConnectPtr conn,
disk->blkdeviotune.write_iops_sec); disk->blkdeviotune.write_iops_sec);
} }
if (virBufferError(&opt)) { if (virBufferCheckError(&opt) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&opt); return virBufferContentAndReset(&opt);
@ -3899,10 +3893,8 @@ qemuBuildDriveDevStr(virDomainDefPtr def,
} }
} }
if (virBufferError(&opt)) { if (virBufferCheckError(&opt) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&opt); return virBufferContentAndReset(&opt);
@ -3975,10 +3967,8 @@ char *qemuBuildFSStr(virDomainFSDefPtr fs,
} }
} }
if (virBufferError(&opt)) { if (virBufferCheckError(&opt) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&opt); return virBufferContentAndReset(&opt);
@ -4009,10 +3999,8 @@ qemuBuildFSDevStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&opt, def, &fs->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&opt, def, &fs->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&opt)) { if (virBufferCheckError(&opt) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&opt); return virBufferContentAndReset(&opt);
@ -4252,10 +4240,8 @@ qemuBuildControllerDevStr(virDomainDefPtr domainDef,
if (qemuBuildDeviceAddressStr(&buf, domainDef, &def->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, domainDef, &def->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -4365,10 +4351,8 @@ qemuBuildNicDevStr(virDomainDefPtr def,
if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX)) if (bootindex && virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOTINDEX))
virBufferAsprintf(&buf, ",bootindex=%d", bootindex); virBufferAsprintf(&buf, ",bootindex=%d", bootindex);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -4502,11 +4486,8 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
virObjectUnref(cfg); virObjectUnref(cfg);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
@ -4530,10 +4511,8 @@ qemuBuildWatchdogDevStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -4571,10 +4550,8 @@ qemuBuildMemballoonDevStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -4598,10 +4575,8 @@ qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev)
goto error; goto error;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -4634,10 +4609,8 @@ qemuBuildUSBInputDevStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -4687,10 +4660,8 @@ qemuBuildSoundDevStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&buf, def, &sound->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, &sound->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -4802,10 +4773,8 @@ qemuBuildDeviceVideoStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&buf, def, &video->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, &video->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -4889,10 +4858,8 @@ qemuBuildPCIHostdevDevStr(virDomainDefPtr def,
if (qemuBuildRomStr(&buf, dev->info, qemuCaps) < 0) if (qemuBuildRomStr(&buf, dev->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5010,10 +4977,8 @@ qemuBuildRedirdevDevStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5050,10 +5015,8 @@ qemuBuildUSBHostdevDevStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5088,10 +5051,8 @@ qemuBuildHubDevStr(virDomainDefPtr def,
if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0)
goto error; goto error;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5157,10 +5118,8 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
} }
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
VIR_FREE(sg); VIR_FREE(sg);
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5222,10 +5181,8 @@ qemuBuildSCSIHostdevDevStr(virDomainDefPtr def,
if (dev->info->bootIndex) if (dev->info->bootIndex)
virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex); virBufferAsprintf(&buf, ",bootindex=%d", dev->info->bootIndex);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
error: error:
@ -5342,10 +5299,8 @@ qemuBuildChrChardevStr(virDomainChrSourceDefPtr dev, const char *alias,
goto error; goto error;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5438,10 +5393,8 @@ qemuBuildChrArgStr(virDomainChrSourceDefPtr dev, const char *prefix)
break; break;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5518,10 +5471,8 @@ qemuBuildVirtioSerialPortDevStr(virDomainChrDefPtr dev,
} else { } else {
virBufferAsprintf(&buf, ",id=%s", dev->info.alias); virBufferAsprintf(&buf, ",id=%s", dev->info.alias);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5550,10 +5501,8 @@ qemuBuildSclpDevStr(virDomainChrDefPtr dev)
} }
virBufferAsprintf(&buf, ",chardev=char%s,id=%s", virBufferAsprintf(&buf, ",chardev=char%s,id=%s",
dev->info.alias, dev->info.alias); dev->info.alias, dev->info.alias);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5703,10 +5652,8 @@ static char *qemuBuildTPMBackendStr(const virDomainDef *def,
goto error; goto error;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5741,10 +5688,8 @@ static char *qemuBuildTPMDevStr(const virDomainDef *def,
virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s", virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s",
model, tpm->info.alias, tpm->info.alias); model, tpm->info.alias, tpm->info.alias);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5777,10 +5722,8 @@ static char *qemuBuildSmbiosBiosStr(virSysinfoDefPtr def)
if (def->bios_release) if (def->bios_release)
virBufferAsprintf(&buf, ",release=%s", def->bios_release); virBufferAsprintf(&buf, ",release=%s", def->bios_release);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5824,10 +5767,8 @@ static char *qemuBuildSmbiosSystemStr(virSysinfoDefPtr def, bool skip_uuid)
if (def->system_family) if (def->system_family)
virBufferAsprintf(&buf, ",family=%s", def->system_family); virBufferAsprintf(&buf, ",family=%s", def->system_family);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -5944,10 +5885,8 @@ qemuBuildClockArgStr(virDomainClockDefPtr def)
} }
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
@ -6185,10 +6124,8 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
} }
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
*opt = virBufferContentAndReset(&buf); *opt = virBufferContentAndReset(&buf);
@ -6390,11 +6327,8 @@ qemuBuildSmpArgStr(const virDomainDef *def,
return NULL; return NULL;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
@ -6432,10 +6366,8 @@ qemuBuildNumaArgStr(const virDomainDef *def, virCommandPtr cmd)
1024) * 1024; 1024) * 1024;
virBufferAsprintf(&buf, ",mem=%d", def->cpu->cells[i].mem / 1024); virBufferAsprintf(&buf, ",mem=%d", def->cpu->cells[i].mem / 1024);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
virCommandAddArgBuffer(cmd, &buf); virCommandAddArgBuffer(cmd, &buf);
} }
@ -7690,10 +7622,8 @@ qemuBuildCommandLine(virConnectPtr conn,
if (boot_nparams > 0) { if (boot_nparams > 0) {
virCommandAddArg(cmd, "-boot"); virCommandAddArg(cmd, "-boot");
if (virBufferError(&boot_buf)) { if (virBufferCheckError(&boot_buf) < 0)
virReportOOMError();
goto error; goto error;
}
if (boot_nparams < 2 || emitBootindex) { if (boot_nparams < 2 || emitBootindex) {
virCommandAddArgBuffer(cmd, &boot_buf); virCommandAddArgBuffer(cmd, &boot_buf);
@ -9167,10 +9097,8 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
} }
} }
if (virBufferError(&cmd)) { if (virBufferCheckError(&cmd) < 0)
virReportOOMError();
goto error; goto error;
}
*deviceStr = virBufferContentAndReset(&cmd); *deviceStr = virBufferContentAndReset(&cmd);
return 0; return 0;

View File

@ -1203,10 +1203,8 @@ qemuConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0)
return NULL; return NULL;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
@ -8005,10 +8003,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].weight); vm->def->blkio.devices[j].weight);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -8034,10 +8030,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].riops); vm->def->blkio.devices[j].riops);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -8063,10 +8057,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].wiops); vm->def->blkio.devices[j].wiops);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -8092,10 +8084,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].rbps); vm->def->blkio.devices[j].rbps);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -8121,10 +8111,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
vm->def->blkio.devices[j].path, vm->def->blkio.devices[j].path,
vm->def->blkio.devices[j].wbps); vm->def->blkio.devices[j].wbps);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (virTypedParameterAssign(param, if (virTypedParameterAssign(param,
@ -8173,10 +8161,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].weight); persistentDef->blkio.devices[j].weight);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -8207,10 +8193,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].riops); persistentDef->blkio.devices[j].riops);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -8240,10 +8224,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].wiops); persistentDef->blkio.devices[j].wiops);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -8273,10 +8255,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].rbps); persistentDef->blkio.devices[j].rbps);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
@ -8307,10 +8287,8 @@ qemuDomainGetBlkioParameters(virDomainPtr dom,
persistentDef->blkio.devices[j].path, persistentDef->blkio.devices[j].path,
persistentDef->blkio.devices[j].wbps); persistentDef->blkio.devices[j].wbps);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
param->value.s = virBufferContentAndReset(&buf); param->value.s = virBufferContentAndReset(&buf);
} }
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0) if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)

View File

@ -666,11 +666,8 @@ static char *qemuMigrationCookieXMLFormatStr(virQEMUDriverPtr driver,
return NULL; return NULL;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
virBufferFreeAndReset(&buf);
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -2297,11 +2297,8 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
/* Migrate to file */ /* Migrate to file */
virBufferEscapeShell(&buf, target); virBufferEscapeShell(&buf, target);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
virBufferFreeAndReset(&buf);
goto cleanup; goto cleanup;
}
safe_target = virBufferContentAndReset(&buf); safe_target = virBufferContentAndReset(&buf);
/* Two dd processes, sharing the same stdout, are necessary to /* Two dd processes, sharing the same stdout, are necessary to

View File

@ -1576,11 +1576,8 @@ int qemuMonitorTextMigrate(qemuMonitorPtr mon,
virBufferAddLit(&extra, " -b"); virBufferAddLit(&extra, " -b");
if (flags & QEMU_MONITOR_MIGRATE_NON_SHARED_INC) if (flags & QEMU_MONITOR_MIGRATE_NON_SHARED_INC)
virBufferAddLit(&extra, " -i"); virBufferAddLit(&extra, " -i");
if (virBufferError(&extra)) { if (virBufferCheckError(&extra) < 0)
virBufferFreeAndReset(&extra);
virReportOOMError();
goto cleanup; goto cleanup;
}
extrastr = virBufferContentAndReset(&extra); extrastr = virBufferContentAndReset(&extra);
if (virAsprintf(&cmd, "migrate %s\"%s\"", extrastr ? extrastr : "", if (virAsprintf(&cmd, "migrate %s\"%s\"", extrastr ? extrastr : "",
@ -2911,10 +2908,8 @@ int qemuMonitorTextSendKey(qemuMonitorPtr mon,
if (holdtime) if (holdtime)
virBufferAsprintf(&buf, " %u", holdtime); virBufferAsprintf(&buf, " %u", holdtime);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return -1; return -1;
}
cmd = virBufferContentAndReset(&buf); cmd = virBufferContentAndReset(&buf);
if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0) if (qemuMonitorHMPCommand(mon, cmd, &reply) < 0)

View File

@ -728,10 +728,8 @@ int virNetSocketNewConnectSSH(const char *nodename,
virCommandAddArgList(cmd, nodename, "sh", "-c", NULL); virCommandAddArgList(cmd, nodename, "sh", "-c", NULL);
virBufferEscapeShell(&buf, netcat); virBufferEscapeShell(&buf, netcat);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0) {
virCommandFree(cmd); virCommandFree(cmd);
virBufferFreeAndReset(&buf);
virReportOOMError();
return -1; return -1;
} }
quoted = virBufferContentAndReset(&buf); quoted = virBufferContentAndReset(&buf);

View File

@ -372,10 +372,8 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
virBufferAsprintf(&buff, "%02hhX:", keyhash[i]); virBufferAsprintf(&buff, "%02hhX:", keyhash[i]);
virBufferTrim(&buff, ":", 1); virBufferTrim(&buff, ":", 1);
if (virBufferError(&buff) != 0) { if (virBufferCheckError(&buff) < 0)
virReportOOMError();
return -1; return -1;
}
keyhashstr = virBufferContentAndReset(&buff); keyhashstr = virBufferContentAndReset(&buff);
@ -439,10 +437,8 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess)
* to port number */ * to port number */
virBufferAsprintf(&buff, "[%s]:%d", sess->hostname, sess->port); virBufferAsprintf(&buff, "[%s]:%d", sess->hostname, sess->port);
if (virBufferError(&buff) != 0) { if (virBufferCheckError(&buff) < 0)
virReportOOMError();
return -1; return -1;
}
hostnameStr = virBufferContentAndReset(&buff); hostnameStr = virBufferContentAndReset(&buff);

View File

@ -760,14 +760,12 @@ virStorageBackendCreateQemuImgOpts(char **opts,
virBufferTrim(&buf, ",", -1); virBufferTrim(&buf, ",", -1);
if (virBufferError(&buf)) if (virBufferCheckError(&buf) < 0)
goto no_memory; goto error;
*opts = virBufferContentAndReset(&buf); *opts = virBufferContentAndReset(&buf);
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return -1; return -1;

View File

@ -188,10 +188,8 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
} }
} }
if (virBufferError(&mon_host)) { if (virBufferCheckError(&mon_host) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
mon_buff = virBufferContentAndReset(&mon_host); mon_buff = virBufferContentAndReset(&mon_host);
VIR_DEBUG("RADOS mon_host has been set to: %s", mon_buff); VIR_DEBUG("RADOS mon_host has been set to: %s", mon_buff);

View File

@ -266,10 +266,8 @@ umlBuildCommandLineNet(virConnectPtr conn,
def->data.socket.port); def->data.socket.port);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);

View File

@ -1843,11 +1843,8 @@ virCommandToString(virCommandPtr cmd)
virBufferEscapeShell(&buf, cmd->args[i]); virBufferEscapeShell(&buf, cmd->args[i]);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -979,11 +979,8 @@ virConfWriteFile(const char *filename, virConfPtr conf)
cur = cur->next; cur = cur->next;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return -1; return -1;
}
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd < 0) { if (fd < 0) {
@ -1035,11 +1032,8 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf)
cur = cur->next; cur = cur->next;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return -1; return -1;
}
use = virBufferUse(&buf); use = virBufferUse(&buf);
content = virBufferContentAndReset(&buf); content = virBufferContentAndReset(&buf);

View File

@ -119,10 +119,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); virBufferAsprintf(&buf, "%d", virtVlan->tag[i]);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
virCommandAddArg(cmd, virBufferCurrentContent(&buf)); virCommandAddArg(cmd, virBufferCurrentContent(&buf));
} else if (virtVlan->nTags) { } else if (virtVlan->nTags) {
virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]); virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]);

View File

@ -1946,10 +1946,8 @@ virStorageFileCanonicalizeFormatPath(char **components,
virBufferAdd(&buf, components[i], -1); virBufferAdd(&buf, components[i], -1);
} }
if (virBufferError(&buf) != 0) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
/* if the output string is empty just return an empty string */ /* if the output string is empty just return an empty string */
if (!(ret = virBufferContentAndReset(&buf))) if (!(ret = virBufferContentAndReset(&buf)))

View File

@ -158,10 +158,8 @@ char *virStringJoin(const char **strings,
virBufferAdd(&buf, delim, -1); virBufferAdd(&buf, delim, -1);
strings++; strings++;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
ret = virBufferContentAndReset(&buf); ret = virBufferContentAndReset(&buf);
if (!ret) if (!ret)
ignore_value(VIR_STRDUP(ret, "")); ignore_value(VIR_STRDUP(ret, ""));
@ -909,10 +907,8 @@ virStringReplace(const char *haystack,
tmp1 = tmp2; tmp1 = tmp2;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -1064,10 +1064,8 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
virBufferAdjustIndent(buf, -2); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</sysinfo>\n"); virBufferAddLit(buf, "</sysinfo>\n");
if (virBufferError(buf)) { if (virBufferCheckError(buf) < 0)
virReportOOMError();
return -1; return -1;
}
return 0; return 0;
} }

View File

@ -94,10 +94,8 @@ char *virSystemdMakeScopeName(const char *name,
virSystemdEscapeName(&buf, name); virSystemdEscapeName(&buf, name);
virBufferAddLit(&buf, ".scope"); virBufferAddLit(&buf, ".scope");
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }
@ -113,10 +111,8 @@ char *virSystemdMakeSliceName(const char *partition)
virSystemdEscapeName(&buf, partition); virSystemdEscapeName(&buf, partition);
virBufferAddLit(&buf, ".slice"); virBufferAddLit(&buf, ".slice");
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -286,11 +286,8 @@ char *virURIFormatParams(virURIPtr uri)
} }
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -3344,10 +3344,8 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
} }
/* Get final VMX output */ /* Get final VMX output */
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
vmx = virBufferContentAndReset(&buffer); vmx = virBufferContentAndReset(&buffer);

View File

@ -659,10 +659,8 @@ xenUnifiedConnectGetSysinfo(virConnectPtr conn ATTRIBUTE_UNUSED,
if (virSysinfoFormat(&buf, hostsysinfo) < 0) if (virSysinfoFormat(&buf, hostsysinfo) < 0)
return NULL; return NULL;
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
return NULL; return NULL;
}
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
} }

View File

@ -505,11 +505,8 @@ xend_op_ext(virConnectPtr xend, const char *path, const char *key, va_list ap)
virBufferAddChar(&buf, '&'); virBufferAddChar(&buf, '&');
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
return -1; return -1;
}
content = virBufferContentAndReset(&buf); content = virBufferContentAndReset(&buf);
VIR_DEBUG("xend op: %s\n", content); VIR_DEBUG("xend op: %s\n", content);
@ -2611,10 +2608,8 @@ xenDaemonDomainSetAutostart(virConnectPtr conn,
goto error; goto error;
} }
if (virBufferError(&buffer)) { if (virBufferCheckError(&buffer) < 0)
virReportOOMError();
goto error; goto error;
}
content = virBufferContentAndReset(&buffer); content = virBufferContentAndReset(&buffer);

View File

@ -284,11 +284,8 @@ mapDomainPinVcpu(unsigned char *cpumap, int maplen)
} }
} }
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
virBufferFreeAndReset(&buf);
return NULL; return NULL;
}
ret = virBufferContentAndReset(&buf); ret = virBufferContentAndReset(&buf);
len = strlen(ret); len = strlen(ret);
if (len > 0 && ret[len - 1] == ',') if (len > 0 && ret[len - 1] == ',')

View File

@ -1693,10 +1693,8 @@ xenFormatSxprChr(virDomainChrDefPtr def,
return -1; return -1;
} }
if (virBufferError(buf)) { if (virBufferCheckError(buf) < 0)
virReportOOMError();
return -1; return -1;
}
return 0; return 0;
} }
@ -2118,10 +2116,8 @@ xenFormatSxprSound(virDomainDefPtr def,
virBufferEscapeSexpr(buf, "%s", str); virBufferEscapeSexpr(buf, "%s", str);
} }
if (virBufferError(buf)) { if (virBufferCheckError(buf) < 0)
virReportOOMError();
return -1; return -1;
}
return 0; return 0;
} }
@ -2551,10 +2547,8 @@ xenFormatSxpr(virConnectPtr conn,
virBufferAddLit(&buf, ")"); /* closes (vm */ virBufferAddLit(&buf, ")"); /* closes (vm */
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto error; goto error;
}
bufout = virBufferContentAndReset(&buf); bufout = virBufferContentAndReset(&buf);
VIR_DEBUG("Formatted sexpr: \n%s", bufout); VIR_DEBUG("Formatted sexpr: \n%s", bufout);

View File

@ -1261,10 +1261,8 @@ xenFormatXMDisk(virConfValuePtr list,
return -1; return -1;
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (VIR_ALLOC(val) < 0) if (VIR_ALLOC(val) < 0)
goto cleanup; goto cleanup;
@ -1300,10 +1298,8 @@ static int xenFormatXMSerial(virConfValuePtr list,
} else { } else {
virBufferAddLit(&buf, "none"); virBufferAddLit(&buf, "none");
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (VIR_ALLOC(val) < 0) if (VIR_ALLOC(val) < 0)
goto cleanup; goto cleanup;
@ -1406,10 +1402,8 @@ static int xenFormatXMNet(virConnectPtr conn,
virBufferAsprintf(&buf, ",vifname=%s", virBufferAsprintf(&buf, ",vifname=%s",
net->ifname); net->ifname);
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (VIR_ALLOC(val) < 0) if (VIR_ALLOC(val) < 0)
goto cleanup; goto cleanup;
@ -1861,11 +1855,8 @@ virConfPtr xenFormatXM(virConnectPtr conn,
virBufferAsprintf(&buf, ",keymap=%s", virBufferAsprintf(&buf, ",keymap=%s",
def->graphics[0]->data.vnc.keymap); def->graphics[0]->data.vnc.keymap);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virBufferFreeAndReset(&buf);
virReportOOMError();
goto cleanup; goto cleanup;
}
vfbstr = virBufferContentAndReset(&buf); vfbstr = virBufferContentAndReset(&buf);

View File

@ -58,10 +58,8 @@ testFilterXML(char *xml)
virBufferStrcat(&buf, *xmlLine, "\n", NULL); virBufferStrcat(&buf, *xmlLine, "\n", NULL);
} }
if (virBufferError(&buf)) { if (virBufferCheckError(&buf) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
ret = virBufferContentAndReset(&buf); ret = virBufferContentAndReset(&buf);