[libvirt PATCH 05/21] util: Use glib memory functions in virLastErrorObject
Ján Tomko
jtomko at redhat.com
Fri Sep 11 15:45:26 UTC 2020
On a Friday in 2020, Tim Wiederhake wrote:
>Signed-off-by: Tim Wiederhake <twiederh at 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200911/feef5284/attachment-0001.sig>
More information about the libvir-list
mailing list