[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt PATCH 05/21] util: Use glib memory functions in virLastErrorObject



On a Friday in 2020, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh redhat com>
---
src/util/virerror.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/util/virerror.c b/src/util/virerror.c
index 4ba99defbb..99a0855b51 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -237,15 +237,17 @@ virErrorCopyNew(virErrorPtr err)
static virErrorPtr
virLastErrorObject(void)
{
-    virErrorPtr err;
+    g_autoptr(virError) err = NULL;
+

This function would also look nicer without g_auto - most of the code
paths don't want to free err.

Jano

    err = virThreadLocalGet(&virLastErr);
-    if (!err) {
-        if (VIR_ALLOC_QUIET(err) < 0)
-            return NULL;
-        if (virThreadLocalSet(&virLastErr, err) < 0)
-            VIR_FREE(err);
-    }
-    return err;
+    if (err)
+        return g_steal_pointer(&err);
+
+    err = g_new0(virError, 1);
+    if (virThreadLocalSet(&virLastErr, err) < 0)
+        return NULL;
+
+    return g_steal_pointer(&err);
}


--
2.26.2

Attachment: signature.asc
Description: PGP signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]