[libvirt] [PATCH 1/5] conf: Get rid of "no_memory" labels

Fabiano Fidêncio fidencio at redhat.com
Fri Dec 20 12:43:11 UTC 2019


As pointed out by Ján Tomko, "no_memory seems suspicious in the times of
abort()".

As libvirt decided to take the path to not report OOM and simply abort
when it happens, let's get rid of the no_memory labels and simplify the
code around them.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 src/conf/capabilities.c | 16 +++-------------
 src/conf/domain_audit.c | 40 ++++++++++------------------------------
 2 files changed, 13 insertions(+), 43 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index da54591c11..82129feaac 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -619,26 +619,16 @@ virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModelPtr secmodel,
                                         const char *type,
                                         const char *label)
 {
-    char *t = NULL, *l = NULL;
-
     if (type == NULL || label == NULL)
         return -1;
 
-    t = g_strdup(type);
-    l = g_strdup(label);
-
     if (VIR_EXPAND_N(secmodel->labels, secmodel->nlabels, 1) < 0)
-        goto no_memory;
+        return -1;
 
-    secmodel->labels[secmodel->nlabels - 1].type = t;
-    secmodel->labels[secmodel->nlabels - 1].label = l;
+    secmodel->labels[secmodel->nlabels - 1].type = g_strdup(type);
+    secmodel->labels[secmodel->nlabels - 1].label = g_strdup(label);
 
     return 0;
-
- no_memory:
-    VIR_FREE(l);
-    VIR_FREE(t);
-    return -1;
 }
 
 
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index a55dcd5f91..fdccc585fb 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -89,12 +89,12 @@ virDomainAuditGenericDev(virDomainObjPtr vm,
                          const char *reason,
                          bool success)
 {
-    char *newdev = NULL;
-    char *olddev = NULL;
+    g_autofree char *newdev = NULL;
+    g_autofree char *olddev = NULL;
+    g_autofree char *vmname = NULL;
+    g_autofree char *oldsrc = NULL;
+    g_autofree char *newsrc = NULL;
     char uuidstr[VIR_UUID_STRING_BUFLEN];
-    char *vmname = NULL;
-    char *oldsrc = NULL;
-    char *newsrc = NULL;
     const char *virt = virDomainAuditGetVirtType(vm->def);
 
     /* if both new and old source aren't provided don't log anything */
@@ -107,29 +107,17 @@ virDomainAuditGenericDev(virDomainObjPtr vm,
     virUUIDFormat(vm->def->uuid, uuidstr);
 
     if (!(vmname = virAuditEncode("vm", vm->def->name)))
-        goto no_memory;
+        return;
 
     if (!(newsrc = virAuditEncode(newdev, VIR_AUDIT_STR(newsrcpath))))
-        goto no_memory;
+        return;
 
     if (!(oldsrc = virAuditEncode(olddev, VIR_AUDIT_STR(oldsrcpath))))
-        goto no_memory;
+        return;
 
     VIR_AUDIT(VIR_AUDIT_RECORD_RESOURCE, success,
               "virt=%s resrc=%s reason=%s %s uuid=%s %s %s",
               virt, type, reason, vmname, uuidstr, oldsrc, newsrc);
-
- cleanup:
-    VIR_FREE(newdev);
-    VIR_FREE(olddev);
-    VIR_FREE(vmname);
-    VIR_FREE(oldsrc);
-    VIR_FREE(newsrc);
-    return;
-
- no_memory:
-    VIR_WARN("OOM while encoding audit message");
-    goto cleanup;
 }
 
 
@@ -957,13 +945,13 @@ virDomainAuditInput(virDomainObjPtr vm,
                     bool success)
 {
     char uuidstr[VIR_UUID_STRING_BUFLEN];
-    char *vmname;
+    g_autofree char *vmname = NULL;
     const char *virt = virDomainAuditGetVirtType(vm->def);
 
     virUUIDFormat(vm->def->uuid, uuidstr);
 
     if (!(vmname = virAuditEncode("vm", vm->def->name)))
-        goto no_memory;
+        return;
 
     switch ((virDomainInputType) input->type) {
     case VIR_DOMAIN_INPUT_TYPE_MOUSE:
@@ -980,12 +968,4 @@ virDomainAuditInput(virDomainObjPtr vm,
     case VIR_DOMAIN_INPUT_TYPE_LAST:
         break;
     }
-
- cleanup:
-    VIR_FREE(vmname);
-    return;
-
- no_memory:
-    VIR_WARN("OOM while encoding audit message");
-    goto cleanup;
 }
-- 
2.24.1




More information about the libvir-list mailing list