[PATCH 1/4] vsh-table: Use g_autofree where possible

Ján Tomko jtomko at redhat.com
Thu Feb 25 12:20:11 UTC 2021


On a Tuesday in 2021, Kristina Hanicova wrote:
>In: vshTableRowNew(), vshTablePrint(), vshTablePrintToStdout().
>
>Signed-off-by: Kristina Hanicova <khanicov at redhat.com>
>---
> tools/vsh-table.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
>
>diff --git a/tools/vsh-table.c b/tools/vsh-table.c
>index d09cc9e14e..2e10abfc90 100644
>--- a/tools/vsh-table.c
>+++ b/tools/vsh-table.c
>@@ -361,8 +359,8 @@ vshTablePrint(vshTablePtr table, bool header)
> {
>     size_t i;
>     size_t j;
>-    size_t *maxwidths;
>-    size_t **widths;
>+    g_autofree size_t *maxwidths = NULL;
>+    g_autofree size_t **widths = NULL;
>     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
>     char *ret = NULL;
>
>@@ -395,10 +393,8 @@ vshTablePrint(vshTablePtr table, bool header)
>     ret = virBufferContentAndReset(&buf);
>
>  cleanup:
>-    VIR_FREE(maxwidths);

>     for (i = 0; i < table->nrows; i++)
>         VIR_FREE(widths[i]);
>-    VIR_FREE(widths);

While this does not change the behavior, mixing g_autofree for the outer
array while using VIR_FREE for the per-row arrays feels incomplete.

Please leave it out of the g_autofree conversion.

Jano

>     return ret;
> }
>
>@@ -416,15 +412,13 @@ void
-------------- 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/20210225/8e37b93a/attachment-0001.sig>


More information about the libvir-list mailing list