file-posix: Don't leak fd in hdev_get_max_segments
PATCH 1/1 file-posix: Don't leak fd in hdev_get_max_segments
--- block/file-posix.c | 1 + 1 file changed, 1 insertion(+)
block/file-posix.c +1 -0
@@ -703,6 +703,7 @@ static int hdev_get_max_segments(const struct stat *st) } out: +close (fd);g_free (sysfspath);return ret;#else
Signature · 1 line
2.9.3
Am 14.03.2017 um 16:43 hat Fam Zheng geschrieben:
Quoted 10 lines
Signed-off-by Fam Zheng <[email protected]>--- block/file-posix.c | 1 + 1 file changed, 1 insertion(+)block/file-posix.c +0
-0
block/file-posix.c static int hdev_get_max_segments(const struct stat *st) · line 706
Quoted 4 lines
block/file-posix.c +1
-0@@ -703,6 +703,7 @@ static int hdev_get_max_segments(const struct stat *st) } out: +close (fd);
Should we make this conditional on fd != -1?
block/file-posix.c static int hdev_get_max_segments(const struct stat *st) · line 709
Quoted 3 lines
block/file-posix.c +0
-0g_free (sysfspath);return ret;#else
Kevin
Quoted 13 lines · Kevin Wolf
Am 14.03.2017 um 16:43 hat Fam Zheng geschrieben:
Quoted 12 lines
Signed-off-by Fam Zheng <[email protected]>--- block/file-posix.c | 1 + 1 file changed, 1 insertion(+)block/file-posix.c +0
-0@@ -703,6 +703,7 @@ static int hdev_get_max_segments(const struct stat *st) }
Quoted 4 lines
block/file-posix.c static int hdev_get_max_segments(const struct stat *st) · line 706
Quoted 2 lines
block/file-posix.c +1
-0out: +close (fd);Should we make this conditional on fd != -1?
OK, that is cleaner.
Fam
Quoted 6 lines
block/file-posix.c static int hdev_get_max_segments(const struct stat *st) · line 709
Quoted 4 lines
block/file-posix.c +0
-0g_free (sysfspath);return ret;#else Kevin
block/file-posix.c static int hdev_get_max_segments(const struct stat *st)
Quoted 10 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/file-posix.c | 1 + 1 file changed, 1 insertion(+)block/file-posix.c +0
-0@@ -703,6 +703,7 @@ static int hdev_get_max_segments(const struct stat *st)
hdev_get_max_segments() is not part of master yet; should this just be treated as a fixup! to a pending patch?
Quoted 8 lines
block/file-posix.c +1
-0} out: +close (fd);g_free (sysfspath);return ret;#else
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Eric Blake
Reviewed-byQuoted 6 lines · Eric Blake
Quoted 5 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/file-posix.c | 1 + 1 file changed, 1 insertion(+)
Quoted 8 lines
block/file-posix.c static int hdev_get_max_segments(const struct stat *st)
Quoted 5 lines
block/file-posix.c +0
-0@@ -703,6 +703,7 @@ static int hdev_get_max_segments(const struct stat *st)
hdev_get_max_segments()is not part of master yet; should this just be treated as a fixup! to a pending patch?
Scratch that - I forgot to 'git pull' on my end.
Commit message could usefully be improved by mentioning commit 9103f1ce as the spot the problem was introduced.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 16 lines · Eric Blake
Quoted 6 lines · Eric Blake
Quoted 5 lines · Fam Zheng
Signed-off-by Fam Zheng <[email protected]>--- block/file-posix.c | 1 + 1 file changed, 1 insertion(+)Quoted 8 lines
block/file-posix.c static int hdev_get_max_segments(const struct stat *st)
Quoted 5 lines
block/file-posix.c +0
-0@@ -703,6 +703,7 @@ static int hdev_get_max_segments(const struct stat *st)
hdev_get_max_segments()is not part of master yet; should this just be treated as a fixup! to a pending patch?
Quoted 7 lines
Scratch that - I forgot to 'git pull' on my end.
Commit message could usefully be improved by mentioning commit
9103f1ceas the spot the problem was introduced.Reviewed-by Eric Blake <[email protected]>
Question: does valgrind or any other tool complain about:
+ if (fd == -1) {
+ ret = -errno;
+ goto out;
+ }
...
+out:
+ close(fd); + g_free(sysfspath); + return ret;
this being a useless syscall to close(-1) ? If so, you need to wrap in an 'if (fd != -1)'
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Am 14.03.2017 um 17:11 hat Eric Blake geschrieben:
Quoted 6 lines · Fam Zheng
Quoted 5 lines
Signed-off-by Fam Zheng <[email protected]>--- block/file-posix.c | 1 + 1 file changed, 1 insertion(+)
Quoted 8 lines
block/file-posix.c static int hdev_get_max_segments(const struct stat *st)
Quoted 5 lines
block/file-posix.c +0
-0@@ -703,6 +703,7 @@ static int hdev_get_max_segments(const struct stat *st)
hdev_get_max_segments()is not part of master yet; should this just be treated as a fixup! to a pending patch?
It is already in master, since yesterday, I think.
Kevin