Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1914)

Unified Diff: native_client_sdk/src/libraries/nacl_io/kernel_object.cc

Issue 795213003: Fix handling of free descriptors when calling dup2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/nacl_io/kernel_object.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
index 8c670f8f789f89dc91cf41755e817dc351a1c3d2..93b2f9a1d5b072e82bb110812a84876a8480a122 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
@@ -253,8 +253,15 @@ void KernelObject::FreeAndReassignFD(int fd,
AUTO_LOCK(handle_lock_);
// If the required FD is larger than the current set, grow the set
- if (fd >= (int)handle_map_.size())
+ if (fd >= (int)handle_map_.size()) {
binji 2014/12/12 18:55:20 use c++-style cast
bradn 2014/12/12 22:58:18 Done.
+ int sz = (int)handle_map_.size();
Sam Clegg 2014/12/12 00:44:40 Move this line outside the condition to avoid call
bradn 2014/12/12 22:58:18 Done.
handle_map_.resize(fd + 1);
Sam Clegg 2014/12/12 00:44:40 A comment here to describe what is happening and w
bradn 2014/12/12 22:58:18 Done.
+ for (; sz < fd; ++sz) {
+ free_fds_.push_back(sz);
+ std::push_heap(free_fds_.begin(), free_fds_.end(),
+ std::greater<int>());
+ }
+ }
// This path will be from an existing handle, and absolute.
handle_map_[fd] = Descriptor_t(handle, path);

Powered by Google App Engine
This is Rietveld 408576698