All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vhost-user-blk: Fix two resource leaks
@ 2020-10-28 14:09 AlexChen
  2020-10-28 15:40 ` Raphael Norwitz
  2020-10-29  6:03 ` [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call AlexChen
  0 siblings, 2 replies; 7+ messages in thread
From: AlexChen @ 2020-10-28 14:09 UTC (permalink / raw)
  To: raphael.norwitz; +Cc: qemu-trivial, qemu-devel

When socket() fails, it returns -1, 0 is the normal return value and should not return

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: AlexChen <alex.chen@huawei.com>
---
 contrib/vhost-user-blk/vhost-user-blk.c   | 2 +-
 contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
index 25eccd02b5..40a2dfc544 100644
--- a/contrib/vhost-user-blk/vhost-user-blk.c
+++ b/contrib/vhost-user-blk/vhost-user-blk.c
@@ -474,7 +474,7 @@ static int unix_sock_new(char *unix_fn)
     assert(unix_fn);

     sock = socket(AF_UNIX, SOCK_STREAM, 0);
-    if (sock <= 0) {
+    if (sock < 0) {
         perror("socket");
         return -1;
     }
diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index 3c912384e9..0f9ba4b2a2 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -320,7 +320,7 @@ static int unix_sock_new(char *unix_fn)
     assert(unix_fn);

     sock = socket(AF_UNIX, SOCK_STREAM, 0);
-    if (sock <= 0) {
+    if (sock < 0) {
         perror("socket");
         return -1;
     }
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] vhost-user-blk: Fix two resource leaks
  2020-10-28 14:09 [PATCH] vhost-user-blk: Fix two resource leaks AlexChen
@ 2020-10-28 15:40 ` Raphael Norwitz
  2020-10-29  5:58   ` AlexChen
  2020-10-29  6:03 ` [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call AlexChen
  1 sibling, 1 reply; 7+ messages in thread
From: Raphael Norwitz @ 2020-10-28 15:40 UTC (permalink / raw)
  To: AlexChen; +Cc: qemu-trivial, QEMU, Raphael Norwitz

The change looks good but I'm not sure I'd call it resource leak in
either case since the failure case kills vhost-user-blk/scsi. In the
commit message maybe rather say "vhost-user-blk/scsi: fix broken error
handling for socket call"?

On Wed, Oct 28, 2020 at 10:10 AM AlexChen <alex.chen@huawei.com> wrote:
>
> When socket() fails, it returns -1, 0 is the normal return value and should not return
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: AlexChen <alex.chen@huawei.com>
> ---
>  contrib/vhost-user-blk/vhost-user-blk.c   | 2 +-
>  contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
> index 25eccd02b5..40a2dfc544 100644
> --- a/contrib/vhost-user-blk/vhost-user-blk.c
> +++ b/contrib/vhost-user-blk/vhost-user-blk.c
> @@ -474,7 +474,7 @@ static int unix_sock_new(char *unix_fn)
>      assert(unix_fn);
>
>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
> -    if (sock <= 0) {
> +    if (sock < 0) {
>          perror("socket");
>          return -1;
>      }
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index 3c912384e9..0f9ba4b2a2 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -320,7 +320,7 @@ static int unix_sock_new(char *unix_fn)
>      assert(unix_fn);
>
>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
> -    if (sock <= 0) {
> +    if (sock < 0) {
>          perror("socket");
>          return -1;
>      }
> --
> 2.19.1
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] vhost-user-blk: Fix two resource leaks
  2020-10-28 15:40 ` Raphael Norwitz
@ 2020-10-29  5:58   ` AlexChen
  0 siblings, 0 replies; 7+ messages in thread
From: AlexChen @ 2020-10-29  5:58 UTC (permalink / raw)
  To: Raphael Norwitz; +Cc: qemu-trivial, QEMU, Raphael Norwitz

On 2020/10/28 23:40, Raphael Norwitz wrote:
> The change looks good but I'm not sure I'd call it resource leak in
> either case since the failure case kills vhost-user-blk/scsi. In the
> commit message maybe rather say "vhost-user-blk/scsi: fix broken error
> handling for socket call"?
>

Thanks for your suggestion. I will modify the commit message in next version.

Thanks,
Alex

> On Wed, Oct 28, 2020 at 10:10 AM AlexChen <alex.chen@huawei.com> wrote:
>>
>> When socket() fails, it returns -1, 0 is the normal return value and should not return
>>
>> Reported-by: Euler Robot <euler.robot@huawei.com>
>> Signed-off-by: AlexChen <alex.chen@huawei.com>
>> ---
>>  contrib/vhost-user-blk/vhost-user-blk.c   | 2 +-
>>  contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
>> index 25eccd02b5..40a2dfc544 100644
>> --- a/contrib/vhost-user-blk/vhost-user-blk.c
>> +++ b/contrib/vhost-user-blk/vhost-user-blk.c
>> @@ -474,7 +474,7 @@ static int unix_sock_new(char *unix_fn)
>>      assert(unix_fn);
>>
>>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
>> -    if (sock <= 0) {
>> +    if (sock < 0) {
>>          perror("socket");
>>          return -1;
>>      }
>> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
>> index 3c912384e9..0f9ba4b2a2 100644
>> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
>> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
>> @@ -320,7 +320,7 @@ static int unix_sock_new(char *unix_fn)
>>      assert(unix_fn);
>>
>>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
>> -    if (sock <= 0) {
>> +    if (sock < 0) {
>>          perror("socket");
>>          return -1;
>>      }
>> --
>> 2.19.1
>>
> .
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call
  2020-10-28 14:09 [PATCH] vhost-user-blk: Fix two resource leaks AlexChen
  2020-10-28 15:40 ` Raphael Norwitz
@ 2020-10-29  6:03 ` AlexChen
  2020-10-29 16:41   ` Raphael Norwitz
                     ` (2 more replies)
  1 sibling, 3 replies; 7+ messages in thread
From: AlexChen @ 2020-10-29  6:03 UTC (permalink / raw)
  To: Raphael Norwitz, QEMU, qemu-trivial

When socket() fails, it returns -1, 0 is the normal return value and should not return error.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: AlexChen <alex.chen@huawei.com>
---
 contrib/vhost-user-blk/vhost-user-blk.c   | 2 +-
 contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
index 25eccd02b5..40a2dfc544 100644
--- a/contrib/vhost-user-blk/vhost-user-blk.c
+++ b/contrib/vhost-user-blk/vhost-user-blk.c
@@ -474,7 +474,7 @@ static int unix_sock_new(char *unix_fn)
     assert(unix_fn);

     sock = socket(AF_UNIX, SOCK_STREAM, 0);
-    if (sock <= 0) {
+    if (sock < 0) {
         perror("socket");
         return -1;
     }
diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index 3c912384e9..0f9ba4b2a2 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -320,7 +320,7 @@ static int unix_sock_new(char *unix_fn)
     assert(unix_fn);

     sock = socket(AF_UNIX, SOCK_STREAM, 0);
-    if (sock <= 0) {
+    if (sock < 0) {
         perror("socket");
         return -1;
     }
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call
  2020-10-29  6:03 ` [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call AlexChen
@ 2020-10-29 16:41   ` Raphael Norwitz
  2020-11-12 15:48   ` Peter Maydell
  2020-11-14 16:46   ` Michael S. Tsirkin
  2 siblings, 0 replies; 7+ messages in thread
From: Raphael Norwitz @ 2020-10-29 16:41 UTC (permalink / raw)
  To: AlexChen; +Cc: qemu-trivial, QEMU

On Thu, Oct 29, 2020 at 2:04 AM AlexChen <alex.chen@huawei.com> wrote:
>
> When socket() fails, it returns -1, 0 is the normal return value and should not return error.
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: AlexChen <alex.chen@huawei.com>

Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>


> ---
>  contrib/vhost-user-blk/vhost-user-blk.c   | 2 +-
>  contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
> index 25eccd02b5..40a2dfc544 100644
> --- a/contrib/vhost-user-blk/vhost-user-blk.c
> +++ b/contrib/vhost-user-blk/vhost-user-blk.c
> @@ -474,7 +474,7 @@ static int unix_sock_new(char *unix_fn)
>      assert(unix_fn);
>
>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
> -    if (sock <= 0) {
> +    if (sock < 0) {
>          perror("socket");
>          return -1;
>      }
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index 3c912384e9..0f9ba4b2a2 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -320,7 +320,7 @@ static int unix_sock_new(char *unix_fn)
>      assert(unix_fn);
>
>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
> -    if (sock <= 0) {
> +    if (sock < 0) {
>          perror("socket");
>          return -1;
>      }
> --
> 2.19.1
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call
  2020-10-29  6:03 ` [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call AlexChen
  2020-10-29 16:41   ` Raphael Norwitz
@ 2020-11-12 15:48   ` Peter Maydell
  2020-11-14 16:46   ` Michael S. Tsirkin
  2 siblings, 0 replies; 7+ messages in thread
From: Peter Maydell @ 2020-11-12 15:48 UTC (permalink / raw)
  To: AlexChen; +Cc: QEMU Trivial, Raphael Norwitz, QEMU, Michael S. Tsirkin

Ping? This is a coverity issue fix which has been reviewed,
whose tree should it go via?

Adding mst to cc list as the listed maintainer.

thanks
-- PMM

On Thu, 29 Oct 2020 at 06:05, AlexChen <alex.chen@huawei.com> wrote:
>
> When socket() fails, it returns -1, 0 is the normal return value and should not return error.
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: AlexChen <alex.chen@huawei.com>
> ---
>  contrib/vhost-user-blk/vhost-user-blk.c   | 2 +-
>  contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
> index 25eccd02b5..40a2dfc544 100644
> --- a/contrib/vhost-user-blk/vhost-user-blk.c
> +++ b/contrib/vhost-user-blk/vhost-user-blk.c
> @@ -474,7 +474,7 @@ static int unix_sock_new(char *unix_fn)
>      assert(unix_fn);
>
>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
> -    if (sock <= 0) {
> +    if (sock < 0) {
>          perror("socket");
>          return -1;
>      }
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index 3c912384e9..0f9ba4b2a2 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -320,7 +320,7 @@ static int unix_sock_new(char *unix_fn)
>      assert(unix_fn);
>
>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
> -    if (sock <= 0) {
> +    if (sock < 0) {
>          perror("socket");
>          return -1;
>      }
> --
> 2.19.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call
  2020-10-29  6:03 ` [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call AlexChen
  2020-10-29 16:41   ` Raphael Norwitz
  2020-11-12 15:48   ` Peter Maydell
@ 2020-11-14 16:46   ` Michael S. Tsirkin
  2 siblings, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2020-11-14 16:46 UTC (permalink / raw)
  To: AlexChen; +Cc: qemu-trivial, Raphael Norwitz, QEMU

On Thu, Oct 29, 2020 at 02:03:52PM +0800, AlexChen wrote:
> When socket() fails, it returns -1, 0 is the normal return value and should not return error.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: AlexChen <alex.chen@huawei.com>

Tagged, thanks!

> ---
>  contrib/vhost-user-blk/vhost-user-blk.c   | 2 +-
>  contrib/vhost-user-scsi/vhost-user-scsi.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/contrib/vhost-user-blk/vhost-user-blk.c b/contrib/vhost-user-blk/vhost-user-blk.c
> index 25eccd02b5..40a2dfc544 100644
> --- a/contrib/vhost-user-blk/vhost-user-blk.c
> +++ b/contrib/vhost-user-blk/vhost-user-blk.c
> @@ -474,7 +474,7 @@ static int unix_sock_new(char *unix_fn)
>      assert(unix_fn);
> 
>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
> -    if (sock <= 0) {
> +    if (sock < 0) {
>          perror("socket");
>          return -1;
>      }
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index 3c912384e9..0f9ba4b2a2 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -320,7 +320,7 @@ static int unix_sock_new(char *unix_fn)
>      assert(unix_fn);
> 
>      sock = socket(AF_UNIX, SOCK_STREAM, 0);
> -    if (sock <= 0) {
> +    if (sock < 0) {
>          perror("socket");
>          return -1;
>      }
> -- 
> 2.19.1
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-11-14 16:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28 14:09 [PATCH] vhost-user-blk: Fix two resource leaks AlexChen
2020-10-28 15:40 ` Raphael Norwitz
2020-10-29  5:58   ` AlexChen
2020-10-29  6:03 ` [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call AlexChen
2020-10-29 16:41   ` Raphael Norwitz
2020-11-12 15:48   ` Peter Maydell
2020-11-14 16:46   ` Michael S. Tsirkin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.