diff --git a/Library/Homebrew/formula_lock.rb b/Library/Homebrew/formula_lock.rb
index 3b3807fd85671846c2e5104b3ab69302073a8959..0eeb27c84e18676dd253a1721923dd118177f6d9 100644
--- a/Library/Homebrew/formula_lock.rb
+++ b/Library/Homebrew/formula_lock.rb
@@ -1,3 +1,5 @@
+require 'fcntl'
+
 class FormulaLock
   LOCKDIR = HOMEBREW_CACHE_FORMULA
 
@@ -33,7 +35,9 @@ class FormulaLock
 
   def get_or_create_lockfile
     if @lockfile.nil? || @lockfile.closed?
-      @path.open(File::RDWR | File::CREAT)
+      @lockfile = @path.open(File::RDWR | File::CREAT)
+      @lockfile.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
+      @lockfile
     else
       @lockfile
     end