]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Use glib memory functions in virLogFilterNew
authorTim Wiederhake <twiederh@redhat.com>
Fri, 11 Sep 2020 11:42:04 +0000 (13:42 +0200)
committerJán Tomko <jtomko@redhat.com>
Fri, 11 Sep 2020 16:19:58 +0000 (18:19 +0200)
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
src/util/virlog.c

index f6d0c6c050b770d1264f62a97ade9c431131c71f..285c130d36caa50d8c9468f14de9a195ed70c6e5 100644 (file)
@@ -1308,7 +1308,6 @@ virLogFilterNew(const char *match,
                 virLogPriority priority)
 {
     virLogFilterPtr ret = NULL;
-    char *mdup = NULL;
     size_t mlen = strlen(match);
 
     if (priority < VIR_LOG_DEBUG || priority > VIR_LOG_ERROR) {
@@ -1317,23 +1316,16 @@ virLogFilterNew(const char *match,
         return NULL;
     }
 
+    ret = g_new0(virLogFilter, 1);
+    ret->priority = priority;
+
     /* We must treat 'foo' as equiv to '*foo*' for g_pattern_match
      * todo substring matches, so add 2 extra bytes
      */
-    if (VIR_ALLOC_N_QUIET(mdup, mlen + 3) < 0)
-        return NULL;
-
-    mdup[0] = '*';
-    memcpy(mdup + 1, match, mlen);
-    mdup[mlen + 1] = '*';
-
-    if (VIR_ALLOC_QUIET(ret) < 0) {
-        VIR_FREE(mdup);
-        return NULL;
-    }
-
-    ret->match = mdup;
-    ret->priority = priority;
+    ret->match = g_new0(char, mlen + 3);
+    ret->match[0] = '*';
+    memcpy(ret->match + 1, match, mlen);
+    ret->match[mlen + 1] = '*';
 
     return ret;
 }