Skip to contentSkip to conversation

file-posix: Don't leak fd in hdev_get_max_segments

PATCH Superseded Fam Zheng 3 participants 7 messages Mar 14, 2017 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

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
index c4c0663..e6170f4 100644
@@ -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
#1 lore raw

Am 14.03.2017 um 16:43 hat Fam Zheng geschrieben:

Quoted 10 lines
---
 block/file-posix.c | 1 +
 1 file changed, 1 insertion(+)
block/file-posix.c +0 -0
index c4c0663..e6170f4 100644

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 -0
     g_free(sysfspath);
     return ret;
 #else

Kevin

author
#2 lore raw
Quoted 13 lines · Kevin Wolf

Am 14.03.2017 um 16:43 hat Fam Zheng geschrieben:

Quoted 12 lines
---
 block/file-posix.c | 1 +
 1 file changed, 1 insertion(+)
block/file-posix.c +0 -0
index c4c0663..e6170f4 100644
@@ -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 -0
 out:
+    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 -0
     g_free(sysfspath);
     return ret;
 #else

Kevin

#3 lore raw
In reply to Fam Zheng

block/file-posix.c static int hdev_get_max_segments(const struct stat *st)

Quoted 10 lines · Fam Zheng
---
 block/file-posix.c | 1 +
 1 file changed, 1 insertion(+)
block/file-posix.c +0 -0
index c4c0663..e6170f4 100644
@@ -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
Reviewed-by
#4 lore raw
Quoted 6 lines · Eric Blake
Quoted 5 lines · Fam Zheng
---
 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
index c4c0663..e6170f4 100644
@@ -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
#5 lore raw
Quoted 16 lines · Eric Blake
Quoted 6 lines · Eric Blake
Quoted 5 lines · Fam Zheng
---
 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
index c4c0663..e6170f4 100644
@@ -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 9103f1ce as the spot the problem was introduced.

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
#6 lore raw
In reply to Eric Blake

Am 14.03.2017 um 17:11 hat Eric Blake geschrieben:

Quoted 6 lines · Fam Zheng
Quoted 5 lines
---
 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
index c4c0663..e6170f4 100644
@@ -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