Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3069

C++ TServerSocket leaks socket on fcntl get or set flags error

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 0.9.2
    • Fix Version/s: 0.9.3
    • Component/s: C++ - Library
    • Labels:
      None

      Description

      Walking through the C++ TServerSocket code, there are opportunities for the newly accepted client socket to leak:

        THRIFT_SOCKET clientSocket = ::accept(serverSocket_,
                                    (struct sockaddr *) &clientAddress,
                                    (socklen_t *) &size);
      
        if (clientSocket == -1) {
          int errno_copy = THRIFT_GET_SOCKET_ERROR;
          GlobalOutput.perror("TServerSocket::acceptImpl() ::accept() ", errno_copy);
          throw TTransportException(TTransportException::UNKNOWN, "accept()", errno_copy);
        }
      
        // Make sure client socket is blocking
        int flags = THRIFT_FCNTL(clientSocket, THRIFT_F_GETFL, 0);
        if (flags == -1) {
          int errno_copy = THRIFT_GET_SOCKET_ERROR;
          GlobalOutput.perror("TServerSocket::acceptImpl() THRIFT_FCNTL() THRIFT_F_GETFL ", errno_copy);
          throw TTransportException(TTransportException::UNKNOWN, "THRIFT_FCNTL(THRIFT_F_GETFL)", errno_copy);
        }
      
        if (-1 == THRIFT_FCNTL(clientSocket, THRIFT_F_SETFL, flags & ~THRIFT_O_NONBLOCK)) {
          int errno_copy = THRIFT_GET_SOCKET_ERROR;
          GlobalOutput.perror("TServerSocket::acceptImpl() THRIFT_FCNTL() THRIFT_F_SETFL ~THRIFT_O_NONBLOCK ", errno_copy);
          throw TTransportException(TTransportException::UNKNOWN, "THRIFT_FCNTL(THRIFT_F_SETFL)", errno_copy);
        }
      

      Specifically in both of the latter error handling cases, clientSocket is not cleaned up. Given this is highly unlikely to occur, I set the priority of this issue to Minor.

        Attachments

          Activity

            People

            • Assignee:
              jking3 James E. King III
              Reporter:
              jking3 James E. King III
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: