Message ID | 5F997B84.9040900@huawei.com |
---|---|
State | New |
Headers | show |
Series | vhost-user-blk: Fix two resource leaks | expand |
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 >
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 >> > . >
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; }
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(-)