[libvirt] [PATCH 2/3] virnetsocket: Resolve Coverity RESOURCE_LEAK

Ján Tomko jtomko at redhat.com
Fri Aug 22 15:51:42 UTC 2014


On 08/22/2014 05:28 PM, John Ferlan wrote:
> Since '1b807f92d' - Coverity complains that in the error paths of
> both virFork() and virProcessWait() that the 'passfd' will not be closed
> 
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>  src/rpc/virnetsocket.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
> index f913365..ce908fa 100644
> --- a/src/rpc/virnetsocket.c
> +++ b/src/rpc/virnetsocket.c
> @@ -593,8 +593,10 @@ int virNetSocketNewConnectUNIX(const char *path,
>           * behaviour on sockets according to POSIX, so it doesn't
>           * work outside Linux.
>           */
> -        if ((pid = virFork()) < 0)
> +        if ((pid = virFork()) < 0) {
> +            VIR_FORCE_CLOSE(passfd);
>              goto error;
> +        }
>  
>          if (pid == 0) {
>              umask(0077);
> @@ -604,8 +606,10 @@ int virNetSocketNewConnectUNIX(const char *path,
>              _exit(EXIT_SUCCESS);
>          }
>  
> -        if (virProcessWait(pid, &status, false) < 0)
> +        if (virProcessWait(pid, &status, false) < 0) {
> +            VIR_FORCE_CLOSE(passfd);
>              goto error;
> +        }
>  
>          if (status != EXIT_SUCCESS) {
>              /*
> 

Unless I'm missing something, passfd will be leaked on all error paths unless
virNetSocketForkDaemon succeeds.

Jan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140822/d7ebb5ac/attachment-0001.sig>


More information about the libvir-list mailing list