[PATCH 27/33] vbox: abort() on allocation failure in UTF8<->UTF16 conversion

Peter Krempa pkrempa at redhat.com
Wed Feb 24 16:17:02 UTC 2021


Trying to report an error on OOM is pointless since error handling
allocates memory.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/vbox/vbox_common.c | 20 --------------------
 src/vbox/vbox_common.h | 15 +++++++++++++--
 2 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 138403b034..ce9bfbf827 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -5465,17 +5465,9 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom,
     }

     VBOX_UTF8_TO_UTF16(def->parent.name, &name);
-    if (!name) {
-        virReportOOMError();
-        goto cleanup;
-    }

     if (def->parent.description) {
         VBOX_UTF8_TO_UTF16(def->parent.description, &description);
-        if (!description) {
-            virReportOOMError();
-            goto cleanup;
-        }
     }

     rc = gVBoxAPI.UIConsole.TakeSnapshot(console, name, description, &progress);
@@ -6475,10 +6467,6 @@ vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
         goto cleanup;
     }
     VBOX_UTF16_TO_UTF8(nameUtf16, &name);
-    if (!name) {
-        virReportOOMError();
-        goto cleanup;
-    }

     ret = virGetDomainSnapshot(dom, name);

@@ -6533,10 +6521,6 @@ vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int flags)
     }

     VBOX_UTF16_TO_UTF8(nameUtf16, &name);
-    if (!name) {
-        virReportOOMError();
-        goto cleanup;
-    }

     ret = virGetDomainSnapshot(dom, name);

@@ -6593,10 +6577,6 @@ static int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
     }

     VBOX_UTF16_TO_UTF8(nameUtf16, &name);
-    if (!name) {
-        virReportOOMError();
-        goto cleanup;
-    }

     ret = STREQ(snapshot->name, name);

diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h
index 8b1fb2ac30..1fb922aaf0 100644
--- a/src/vbox/vbox_common.h
+++ b/src/vbox/vbox_common.h
@@ -391,8 +391,19 @@ typedef nsISupports IKeyboard;
         } \
     } while (0)

-#define VBOX_UTF16_TO_UTF8(arg1, arg2)  gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2)
-#define VBOX_UTF8_TO_UTF16(arg1, arg2)  gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2)
+#define VBOX_UTF16_TO_UTF8(arg1, arg2) \
+    do { \
+        gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2); \
+        if (!*(arg2)) \
+            abort(); \
+    } while (0)
+
+#define VBOX_UTF8_TO_UTF16(arg1, arg2) \
+    do { \
+        gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2); \
+        if (!*(arg2)) \
+            abort(); \
+    } while (0)

 #define VBOX_ADDREF(arg)                gVBoxAPI.nsUISupports.AddRef((void *)(arg))

-- 
2.29.2




More information about the libvir-list mailing list