mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
vsh-table: Use g_autofree where possible
In: vshTableRowNew(), vshTablePrint(), vshTablePrintToStdout(). Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
7dd7ddac50
commit
d64f3f763f
@ -98,14 +98,12 @@ vshTableRowNew(const char *arg, va_list ap)
|
|||||||
row = g_new0(vshTableRow, 1);
|
row = g_new0(vshTableRow, 1);
|
||||||
|
|
||||||
while (arg) {
|
while (arg) {
|
||||||
char *tmp = NULL;
|
g_autofree char *tmp = NULL;
|
||||||
|
|
||||||
tmp = g_strdup(arg);
|
tmp = g_strdup(arg);
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(row->cells, row->ncells, tmp) < 0) {
|
if (VIR_APPEND_ELEMENT(row->cells, row->ncells, tmp) < 0)
|
||||||
VIR_FREE(tmp);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
arg = va_arg(ap, const char *);
|
arg = va_arg(ap, const char *);
|
||||||
}
|
}
|
||||||
@ -361,7 +359,7 @@ vshTablePrint(vshTablePtr table, bool header)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t j;
|
size_t j;
|
||||||
size_t *maxwidths;
|
g_autofree size_t *maxwidths = NULL;
|
||||||
size_t **widths;
|
size_t **widths;
|
||||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
@ -395,7 +393,6 @@ vshTablePrint(vshTablePtr table, bool header)
|
|||||||
ret = virBufferContentAndReset(&buf);
|
ret = virBufferContentAndReset(&buf);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(maxwidths);
|
|
||||||
for (i = 0; i < table->nrows; i++)
|
for (i = 0; i < table->nrows; i++)
|
||||||
VIR_FREE(widths[i]);
|
VIR_FREE(widths[i]);
|
||||||
VIR_FREE(widths);
|
VIR_FREE(widths);
|
||||||
@ -416,15 +413,13 @@ void
|
|||||||
vshTablePrintToStdout(vshTablePtr table, vshControl *ctl)
|
vshTablePrintToStdout(vshTablePtr table, vshControl *ctl)
|
||||||
{
|
{
|
||||||
bool header;
|
bool header;
|
||||||
char *out;
|
g_autofree char *out = NULL;
|
||||||
|
|
||||||
header = ctl ? !ctl->quiet : true;
|
header = ctl ? !ctl->quiet : true;
|
||||||
|
|
||||||
out = vshTablePrintToString(table, header);
|
out = vshTablePrintToString(table, header);
|
||||||
if (out)
|
if (out)
|
||||||
vshPrint(ctl, "%s", out);
|
vshPrint(ctl, "%s", out);
|
||||||
|
|
||||||
VIR_FREE(out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user