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

Unified Diff: libraries/nacl-mounts/util/SlotAllocator.h

Issue 10832154: Fix dup and dup2 in nacl-mounts (Closed) Base URL: http://naclports.googlecode.com/svn/trunk/src/
Patch Set: Created 8 years, 4 months 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 | « libraries/nacl-mounts/test.nacl/Makefile ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libraries/nacl-mounts/util/SlotAllocator.h
===================================================================
--- libraries/nacl-mounts/util/SlotAllocator.h (revision 611)
+++ libraries/nacl-mounts/util/SlotAllocator.h (working copy)
@@ -81,18 +81,17 @@
template <class T>
int SlotAllocator<T>::AllocAt(int fd) {
- int prev_size = slots_.size();
if (slots_.size() < fd + 1) {
+ int prev_size = slots_.size();
slots_.resize(fd + 1);
- } else {
- if (free_fds_.find(fd) != free_fds_.end()) {
- slots_[fd] = new T;
- for (int i = prev_size; i < fd; ++i) free_fds_.insert(i);
- } else {
- return -1;
- }
+ for (int i = prev_size; i < fd + 1; ++i) free_fds_.insert(i);
}
- return fd;
+
+ if (free_fds_.erase(fd)) {
+ slots_[fd] = new T;
+ return fd;
+ }
+ return -1;
}
template <class T>
« no previous file with comments | « libraries/nacl-mounts/test.nacl/Makefile ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698