Message ID | 1426303825-9040-1-git-send-email-zhaoshenglong@huawei.com |
---|---|
State | New |
Headers | show |
Am 14.03.2015 um 04:30 schrieb Shannon Zhao: > It's detected by coverity. Close the dirfd. > > Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com> > Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org> > --- > qga/commands-posix.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/qga/commands-posix.c b/qga/commands-posix.c > index d5bb5cb..cbf1c80 100644 > --- a/qga/commands-posix.c > +++ b/qga/commands-posix.c > @@ -2285,6 +2285,7 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) > ga_read_sysfs_file(dirfd, "block_size_bytes", buf, 20, &local_err); Why not closing it here? It's no longer needed. > if (local_err) { > g_free(buf); > + close(dirfd); > error_propagate(errp, local_err); > return NULL; > } > @@ -2293,6 +2294,7 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) > info->size = strtol(buf, NULL, 16); /* the unit is bytes */ > > g_free(buf); > + close(dirfd); > > return info; > }
On 2015/3/14 14:54, Stefan Weil wrote: > Am 14.03.2015 um 04:30 schrieb Shannon Zhao: >> It's detected by coverity. Close the dirfd. >> >> Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com> >> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org> >> --- >> qga/commands-posix.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/qga/commands-posix.c b/qga/commands-posix.c >> index d5bb5cb..cbf1c80 100644 >> --- a/qga/commands-posix.c >> +++ b/qga/commands-posix.c >> @@ -2285,6 +2285,7 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) >> ga_read_sysfs_file(dirfd, "block_size_bytes", buf, 20, &local_err); > > Why not closing it here? It's no longer needed. > Ok, will fix this. Thanks, Shannon >> if (local_err) { >> g_free(buf); >> + close(dirfd); >> error_propagate(errp, local_err); >> return NULL; >> } >> @@ -2293,6 +2294,7 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) >> info->size = strtol(buf, NULL, 16); /* the unit is bytes */ >> g_free(buf); >> + close(dirfd); >> return info; >> } > > > . >
diff --git a/qga/commands-posix.c b/qga/commands-posix.c index d5bb5cb..cbf1c80 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2285,6 +2285,7 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) ga_read_sysfs_file(dirfd, "block_size_bytes", buf, 20, &local_err); if (local_err) { g_free(buf); + close(dirfd); error_propagate(errp, local_err); return NULL; } @@ -2293,6 +2294,7 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) info->size = strtol(buf, NULL, 16); /* the unit is bytes */ g_free(buf); + close(dirfd); return info; }