[Libguestfs] [PATCH libguestfs v2 2/3] daemon: Add filter_list utility function.

Pino Toscano ptoscano at redhat.com
Tue Mar 17 11:54:22 UTC 2020


On Monday, 16 March 2020 14:59:28 CET Richard W.M. Jones wrote:
> diff --git a/daemon/utils.c b/daemon/utils.c
> index 1cf1b07f6..21008b40e 100644
> --- a/daemon/utils.c
> +++ b/daemon/utils.c
> @@ -24,6 +24,7 @@
>  
>  #include <stdio.h>
>  #include <stdlib.h>
> +#include <stdbool.h>

Since daemon.h now includes stdbool.h, this include is reduntand.

> +/**
> + * Filter a list of strings.  Returns a newly allocated list of only
> + * the strings where C<p (str) == true>.
> + *
> + * B<Note> it does not copy the strings, be careful not to double-free
> + * them.
> + */
> +char **
> +filter_list (bool (*p) (const char *str), char **strs)
> +{
> +  DECLARE_STRINGSBUF (ret);

Theoretically speaking, this stringsbuf is leaked on error;
CLEANUP_FREE_STRINGSBUF can't be used though, as it frees also the
strings and not just the string array.

(Same note as in patch #1)

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20200317/97c68565/attachment.sig>


More information about the Libguestfs mailing list