[PATCH 1/4] vsh-table: Use g_autofree where possible
Ján Tomko
jtomko at redhat.com
Mon Mar 1 15:54:00 UTC 2021
On a Thursday in 2021, Michal Privoznik wrote:
>On 2/25/21 1:20 PM, Ján Tomko wrote:
>>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.
>
>Any idea what would make it feel complete again?
>
Freeing all the memory associated with 'widths' automatically, or none
of it.
So either:
* introduce a new typedef for 'size_t **' and define a cleanup function
for it that does that
* use a different data type (does GLib have one that could do this for
us?)
But both seem out of scope of a simple g_autofree cleanup.
Jano
>Michal
>
-------------- 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/20210301/a437352f/attachment-0001.sig>
More information about the libvir-list
mailing list