Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d8df0e9 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Crash if too many open files

If there are too many open files, and we can't dup a socket because we
received EMFILE or ENFILE, let's crash immediately to make this problem
obvious.
Otherwise, we are simply propagating null pointers through the system
and witness null pointer dereference later (in the good cases), or
undefined behaviour.

Bug: 141111452
Test: none
Change-Id: I012bc050e5246456e00c22f0c17a5752b2708875
parent 061e0af2
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -362,6 +362,13 @@ sp<InputChannel> InputChannel::dup() const {
    if (!newFd.ok()) {
        ALOGE("Could not duplicate fd %i for channel %s: %s", getFd(), mName.c_str(),
              strerror(errno));
        const bool hitFdLimit = errno == EMFILE || errno == ENFILE;
        // If this process is out of file descriptors, then throwing that might end up exploding
        // on the other side of a binder call, which isn't really helpful.
        // Better to just crash here and hope that the FD leak is slow.
        // Other failures could be client errors, so we still propagate those back to the caller.
        LOG_ALWAYS_FATAL_IF(hitFdLimit, "Too many open files, could not duplicate input channel %s",
                            getName().c_str());
        return nullptr;
    }
    return InputChannel::create(mName, std::move(newFd));