From 548d7fb26165ace003cb04e9811fa3a8fbd6c9cf Mon Sep 17 00:00:00 2001 From: Changli Gao Date: Mon, 21 Nov 2016 12:09:33 -0800 Subject: [PATCH] Fix fd leak when using direct IOs Summary: We should close the fd, before overriding it. This bug was introduced by f89caa127baa086cb100976b14da1a531cf0e823 Closes https://github.com/facebook/rocksdb/pull/1553 Differential Revision: D4214101 Pulled By: siying fbshipit-source-id: 0d65de0 --- util/env_posix.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/env_posix.cc b/util/env_posix.cc index 01f4dc515..660ecdf5b 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -157,6 +157,7 @@ class PosixEnv : public Env { *result = nullptr; return IOError(fname, errno); } else if (options.use_direct_reads && !options.use_mmap_writes) { + fclose(f); #ifdef OS_MACOSX int flags = O_RDONLY; #else @@ -215,6 +216,7 @@ class PosixEnv : public Env { } close(fd); } else if (options.use_direct_reads) { + close(fd); #ifdef OS_MACOSX int flags = O_RDONLY; #else @@ -269,6 +271,7 @@ class PosixEnv : public Env { if (options.use_mmap_writes && !forceMmapOff) { result->reset(new PosixMmapFile(fname, fd, page_size_, options)); } else if (options.use_direct_writes) { + close(fd); #ifdef OS_MACOSX int flags = O_WRONLY | O_APPEND | O_TRUNC | O_CREAT; #else