[PATCH 05/15] virbitmaptest: test13: Refactor memory cleanup

Ján Tomko jtomko at redhat.com
Fri Oct 2 08:06:35 UTC 2020


On a Friday in 2020, Peter Krempa wrote:
>Move scope of variables and get rid of the 'cleanup' section.
>
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> tests/virbitmaptest.c | 32 +++++++++++---------------------
> 1 file changed, 11 insertions(+), 21 deletions(-)
>
>diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c
>index e1a49bfe35..1578cd0612 100644
>--- a/tests/virbitmaptest.c
>+++ b/tests/virbitmaptest.c
>@@ -670,37 +670,27 @@ test12(const void *opaque G_GNUC_UNUSED)
> static int
> test13(const void *opaque G_GNUC_UNUSED)
> {
>-    virBitmapPtr map = NULL;
>     const char *strings[] = { "1234feebee", "000c0fefe" };
>-    char *str = NULL;
>     size_t i = 0;
>-    int ret = -1;
>
>     for (i = 0; i < G_N_ELEMENTS(strings); i++) {
>-        map = virBitmapNewString(strings[i]);
>-        if (!map)
>-            goto cleanup;
>+        g_autoptr(virBitmap) map = NULL;
>+        g_autofree char *str = NULL;
>
>-        str = virBitmapToString(map);
>-        if (!str)
>-            goto cleanup;
>+        if (!(map = virBitmapNewString(strings[i])))
>+            return -1;
>+
>+        if (!(str = virBitmapToString(map)))
>+            return -1;
>
>         if (STRNEQ(strings[i], str)) {
>-            fprintf(stderr, "\n expected bitmap string '%s' actual string "
>-                    "'%s'\n", strings[i], str);
>-            goto cleanup;
>+            fprintf(stderr, "\n expected bitmap string '%s' actual string '%s'\n",
>+                    strings[i], str);

You also altered the error message.

>+            return -1;
>         }
>-

With that at least mentioned in the commit message:
Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- 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/20201002/5bc27710/attachment-0001.sig>


More information about the libvir-list mailing list