vhost-user-blk: Fix two resource leaks
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
@@ -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
@@ -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
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 returnReported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>--- 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@@ -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@@ -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
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 returnReported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>--- 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@@ -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@@ -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
.
PATCH v2 1/1 vhost-user-blk/scsi: Fix broken error handling for socket call
In reply to AlexChenWhen 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
@@ -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
@@ -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
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.Reported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>
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@@ -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@@ -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
Re: [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call
In reply to AlexChenPing? 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.Reported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>--- 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@@ -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@@ -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
Re: [PATCH V2] vhost-user-blk/scsi: Fix broken error handling for socket call
In reply to AlexChenQuoted 4 lines · AlexChen
When
socket()fails, it returns -1, 0 is the normal return value and should not return error.Reported-by Euler Robot <[email protected]>Signed-off-by AlexChen <[email protected]>
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@@ -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@@ -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