summaryrefslogtreecommitdiffstats
path: root/gluster
diff options
context:
space:
mode:
authorPrashanth Pai <ppai@redhat.com>2016-03-03 17:25:48 +0530
committerThiago da Silva <thiago@redhat.com>2016-03-08 11:01:38 -0800
commit25188ca49950267a74b35aab1359bd5d3b919fc7 (patch)
treeb8b4ec27e3ddbf9a3ecf7c2ae75d28cf6bebc94b /gluster
parent7392f4626609da910a2c98c14b8380419613635d (diff)
Fix dup fd leak
A fd was not being closed after it was duplicated. This code path can be easily hit when doing a GET on a file that needs Etag (md5sum) to be recalculated. Change-Id: Ib2e10d990b9b2e1fa85d0079767892de8c8d4eec Signed-off-by: Prashanth Pai <ppai@redhat.com> Reviewed-on: http://review.gluster.org/13593 Reviewed-by: Thiago da Silva <thiago@redhat.com> Tested-by: Thiago da Silva <thiago@redhat.com>
Diffstat (limited to 'gluster')
-rw-r--r--gluster/swift/common/utils.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/gluster/swift/common/utils.py b/gluster/swift/common/utils.py
index 3bcd074..ded2f0b 100644
--- a/gluster/swift/common/utils.py
+++ b/gluster/swift/common/utils.py
@@ -415,19 +415,26 @@ def _get_etag(path_or_fd):
Since we don't have that we should yield after each chunk read and
computed so that we don't consume the worker thread.
"""
+ etag = ''
if isinstance(path_or_fd, int):
# We are given a file descriptor, so this is an invocation from the
# DiskFile.open() method.
fd = path_or_fd
- etag = _read_for_etag(do_dup(fd))
- do_lseek(fd, 0, os.SEEK_SET)
+ dup_fd = do_dup(fd)
+ try:
+ etag = _read_for_etag(dup_fd)
+ do_lseek(fd, 0, os.SEEK_SET)
+ finally:
+ do_close(dup_fd)
else:
# We are given a path to the object when the DiskDir.list_objects_iter
# method invokes us.
path = path_or_fd
fd = do_open(path, os.O_RDONLY)
- etag = _read_for_etag(fd)
- do_close(fd)
+ try:
+ etag = _read_for_etag(fd)
+ finally:
+ do_close(fd)
return etag