Skip to contentSkip to conversation

vhost-user-blk: Fix two resource leaks

PATCH In review AlexChen 4 participants 7 messages Oct 28, 2020 – Nov 14, 2020

lore
Share & tools
lore

AlexChen

author
#0 lore raw

PATCH 1/1 vhost-user-blk: Fix two resource leaks

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

---
 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(-)
contrib/vhost-user-blk/vhost-user-blk.c +1 -1
index 25eccd02b5..40a2dfc544 100644
@@ -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;
     }
contrib/vhost-user-scsi/vhost-user-scsi.c +1 -1
index 3c912384e9..0f9ba4b2a2 100644
@@ -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;
     }
Signature · 1 line
2.19.1
#1 lore raw

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"?

Quoted 39 lines · AlexChen

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

---
 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(-)
contrib/vhost-user-blk/vhost-user-blk.c +1 -1
index 25eccd02b5..40a2dfc544 100644
@@ -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;
     }
contrib/vhost-user-scsi/vhost-user-scsi.c +1 -2
index 3c912384e9..0f9ba4b2a2 100644
@@ -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

author
#2 lore raw
Quoted 5 lines · 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"?

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

Thanks,
Alex

Quoted 42 lines · AlexChen
Quoted 37 lines

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

---
 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(-)
contrib/vhost-user-blk/vhost-user-blk.c +1 -1
index 25eccd02b5..40a2dfc544 100644
@@ -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;
     }
contrib/vhost-user-scsi/vhost-user-scsi.c +1 -2
index 3c912384e9..0f9ba4b2a2 100644
@@ -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;
     }
--
Quoted 2 lines

2.19.1

.

author
#3 lore raw

PATCH v2 1/1 vhost-user-blk/scsi: Fix broken error handling for socket call

In reply to AlexChen

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

---
 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(-)
contrib/vhost-user-blk/vhost-user-blk.c +1 -1
index 25eccd02b5..40a2dfc544 100644
@@ -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;
     }
contrib/vhost-user-scsi/vhost-user-scsi.c +1 -1
index 3c912384e9..0f9ba4b2a2 100644
@@ -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;
     }
Signature · 1 line
2.19.1
Reviewed-by on v2 1/1
#4 lore raw

Re: [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call

Quoted 5 lines · AlexChen

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

Quoted 34 lines
---
 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(-)
contrib/vhost-user-blk/vhost-user-blk.c +1 -1
index 25eccd02b5..40a2dfc544 100644
@@ -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;
     }
contrib/vhost-user-scsi/vhost-user-scsi.c +1 -2
index 3c912384e9..0f9ba4b2a2 100644
@@ -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

#5 lore raw

Re: [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call

In reply to AlexChen

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

Quoted 38 lines · AlexChen

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

---
 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(-)
contrib/vhost-user-blk/vhost-user-blk.c +1 -1
index 25eccd02b5..40a2dfc544 100644
@@ -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;
     }
contrib/vhost-user-scsi/vhost-user-scsi.c +1 -2
index 3c912384e9..0f9ba4b2a2 100644
@@ -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

#6 lore raw

Re: [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call

In reply to AlexChen
Quoted 4 lines · AlexChen

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

Tagged, thanks!

Quoted 34 lines
---
 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(-)
contrib/vhost-user-blk/vhost-user-blk.c +1 -1
index 25eccd02b5..40a2dfc544 100644
@@ -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;
     }
contrib/vhost-user-scsi/vhost-user-scsi.c +1 -1
index 3c912384e9..0f9ba4b2a2 100644
@@ -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;
     }
Signature · 1 line
2.19.1