[PATCH 2/5] cmdStartGetFDs: Modernize

Ján Tomko jtomko at redhat.com
Thu Feb 3 16:55:25 UTC 2022


On a Thursday in 2022, Peter Krempa wrote:
>Calculate the length of the FD list beforehand to avoid multiple
>expansions and mainly simplify the code and use automatic freeing to
>remove the error code path.
>
>Signed-off-by: Peter Krempa <pkrempa at redhat.com>
>---
> tools/virsh-domain.c | 18 +++++++-----------
> 1 file changed, 7 insertions(+), 11 deletions(-)
>
>diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
>index 43d310f2af..b4cb7193a7 100644
>--- a/tools/virsh-domain.c
>+++ b/tools/virsh-domain.c
>@@ -4021,7 +4021,7 @@ cmdStartGetFDs(vshControl *ctl,
> {
>     const char *fdopt;
>     g_auto(GStrv) fdlist = NULL;
>-    int *fds = NULL;
>+    g_autofree int *fds = NULL;
>     size_t nfds = 0;
>     size_t i;
>
>@@ -4036,23 +4036,19 @@ cmdStartGetFDs(vshControl *ctl,
>         return -1;
>     }
>
>+    nfds = g_strv_length(fdlist);
>+    fds = g_new0(int, nfds);
>+
>     for (i = 0; fdlist[i] != NULL; i++) {

Should nfds be used in the for loop condition too?

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/20220203/2c56cb80/attachment-0001.sig>


More information about the libvir-list mailing list