mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 09:57:26 +03:00
vsh: Simplify bailing out on OOM conditions
When we hit OOM it doesn't really make sense to format the error message by attempting to allocate it. Introduce a simple helper that prints a static message and terminates the execution.
This commit is contained in:
parent
9cb8b0e5a4
commit
018010f05c
19
tools/vsh.c
19
tools/vsh.c
@ -77,6 +77,18 @@ const vshCmdDef *cmdSet;
|
|||||||
/* Bypass header poison */
|
/* Bypass header poison */
|
||||||
#undef strdup
|
#undef strdup
|
||||||
|
|
||||||
|
|
||||||
|
/* simple handler for oom conditions */
|
||||||
|
static void
|
||||||
|
vshErrorOOM(void)
|
||||||
|
{
|
||||||
|
fflush(stdout);
|
||||||
|
fputs(_("error: Out of memory\n"), stderr);
|
||||||
|
fflush(stderr);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
vshPrettyCapacity(unsigned long long val, const char **unit)
|
vshPrettyCapacity(unsigned long long val, const char **unit)
|
||||||
{
|
{
|
||||||
@ -1700,11 +1712,8 @@ vshPrintExtra(vshControl *ctl, const char *format, ...)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
if (virVasprintf(&str, format, ap) < 0) {
|
if (virVasprintfQuiet(&str, format, ap) < 0)
|
||||||
vshError(ctl, "%s", _("Out of memory"));
|
vshErrorOOM();
|
||||||
va_end(ap);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
fputs(str, stdout);
|
fputs(str, stdout);
|
||||||
VIR_FREE(str);
|
VIR_FREE(str);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user