]> xenbits.xensource.com Git - libvirt.git/commitdiff
vsh: Simplify bailing out on OOM conditions
authorPeter Krempa <pkrempa@redhat.com>
Fri, 12 Feb 2016 13:00:28 +0000 (14:00 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 15 Feb 2016 12:31:12 +0000 (13:31 +0100)
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.

tools/vsh.c

index 073347a390c68096df52bd62d8f93d686ad0daa5..91e3106aba7eeb5e546b10d4b10933c79a0bfc55 100644 (file)
@@ -77,6 +77,18 @@ const vshCmdDef *cmdSet;
 /* Bypass header poison */
 #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
 vshPrettyCapacity(unsigned long long val, const char **unit)
 {
@@ -1700,11 +1712,8 @@ vshPrintExtra(vshControl *ctl, const char *format, ...)
         return;
 
     va_start(ap, format);
-    if (virVasprintf(&str, format, ap) < 0) {
-        vshError(ctl, "%s", _("Out of memory"));
-        va_end(ap);
-        return;
-    }
+    if (virVasprintfQuiet(&str, format, ap) < 0)
+        vshErrorOOM();
     va_end(ap);
     fputs(str, stdout);
     VIR_FREE(str);