summaryrefslogtreecommitdiffstats
path: root/base/file_descriptor_shuffle.cc
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-10 19:41:43 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-10 19:41:43 +0000
commita0607da9446e3ec76a7ced32502f8c7e71654d53 (patch)
tree958a5b77aa00de5981641531e683b565c6d5b3cf /base/file_descriptor_shuffle.cc
parent651b77c761749949fc7f148e3c20fe203a61bf7d (diff)
downloadchromium_src-a0607da9446e3ec76a7ced32502f8c7e71654d53.zip
chromium_src-a0607da9446e3ec76a7ced32502f8c7e71654d53.tar.gz
chromium_src-a0607da9446e3ec76a7ced32502f8c7e71654d53.tar.bz2
Revert "POSIX: don't allocate memory after forking."
Appears to break tlslite on the Mac. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41190 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_descriptor_shuffle.cc')
-rw-r--r--base/file_descriptor_shuffle.cc36
1 files changed, 12 insertions, 24 deletions
diff --git a/base/file_descriptor_shuffle.cc b/base/file_descriptor_shuffle.cc
index 2bb156b..e722a29 100644
--- a/base/file_descriptor_shuffle.cc
+++ b/base/file_descriptor_shuffle.cc
@@ -12,36 +12,28 @@
namespace base {
-bool PerformInjectiveMultimapDestructive(
- InjectiveMultimap* m, InjectionDelegate* delegate) {
- static const size_t kMaxExtraFDs = 16;
- int extra_fds[kMaxExtraFDs];
- unsigned next_extra_fd = 0;
-
- // DANGER: this function may not allocate.
+bool PerformInjectiveMultimap(const InjectiveMultimap& m_in,
+ InjectionDelegate* delegate) {
+ InjectiveMultimap m(m_in);
+ std::vector<int> extra_fds;
- for (InjectiveMultimap::iterator i = m->begin(); i != m->end(); ++i) {
+ for (InjectiveMultimap::iterator i = m.begin(); i != m.end(); ++i) {
int temp_fd = -1;
// We DCHECK the injectiveness of the mapping.
- for (InjectiveMultimap::iterator j = i + 1; j != m->end(); ++j) {
+ for (InjectiveMultimap::iterator j = i + 1; j != m.end(); ++j) {
DCHECK(i->dest != j->dest) << "Both fd " << i->source
<< " and " << j->source << " map to " << i->dest;
}
const bool is_identity = i->source == i->dest;
- for (InjectiveMultimap::iterator j = i + 1; j != m->end(); ++j) {
+ for (InjectiveMultimap::iterator j = i + 1; j != m.end(); ++j) {
if (!is_identity && i->dest == j->source) {
if (temp_fd == -1) {
if (!delegate->Duplicate(&temp_fd, i->dest))
return false;
- if (next_extra_fd < kMaxExtraFDs) {
- extra_fds[next_extra_fd++] = temp_fd;
- } else {
- RAW_LOG(ERROR, "PerformInjectiveMultimapDestructive overflowed "
- "extra_fds. Leaking file descriptors!");
- }
+ extra_fds.push_back(temp_fd);
}
j->source = temp_fd;
@@ -66,18 +58,14 @@ bool PerformInjectiveMultimapDestructive(
delegate->Close(i->source);
}
- for (unsigned i = 0; i < next_extra_fd; i++)
- delegate->Close(extra_fds[i]);
+ for (std::vector<int>::const_iterator
+ i = extra_fds.begin(); i != extra_fds.end(); ++i) {
+ delegate->Close(*i);
+ }
return true;
}
-bool PerformInjectiveMultimap(const InjectiveMultimap& m_in,
- InjectionDelegate* delegate) {
- InjectiveMultimap m(m_in);
- return PerformInjectiveMultimapDestructive(&m, delegate);
-}
-
bool FileDescriptorTableInjection::Duplicate(int* result, int fd) {
*result = HANDLE_EINTR(dup(fd));
return *result >= 0;