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

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: fixes 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
« no previous file with comments | « no previous file | native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..18c9f932ed203d55da01bbaaaae424e541fbd76a 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_object.cc
@@ -252,9 +252,19 @@ void KernelObject::FreeAndReassignFD(int fd,
} else {
AUTO_LOCK(handle_lock_);
- // If the required FD is larger than the current set, grow the set
- if (fd >= (int)handle_map_.size())
+ // If the required FD is larger than the current set, grow the set.
+ int sz = static_cast<int>(handle_map_.size());
+ if (fd >= sz) {
+ // Expand the handle map to include all the extra descriptors
+ // up to and including fd.
handle_map_.resize(fd + 1);
+ // Add all the new descriptors, except fd, to the free list.
+ 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);
« no previous file with comments | « no previous file | native_client_sdk/src/tests/nacl_io_test/kernel_proxy_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698