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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 0.9.2
    • 0.9.3
    • C++ - Library
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: