Uploaded image for project: 'Mesos'
  1. Mesos
  2. MESOS-2412

Potential memleak(s) in stout/os.hpp

    XMLWordPrintableJSON

    Details

    • Target Version/s:
    • Sprint:
      Mesosphere Q1 Sprint 4 - 3/6

      Description

      Coverity picked up this potential memleak in os.hpp where we do not delete buffer in the else case. The exact same pattern occurs in getuid(const Option<std::string>& user = None()).
      The corresponding CID 1230371 and 1230371.

      inline Result<gid_t> getgid(const Option<std::string>& user = None())
      ...
        while (true) {
          char* buffer = new char[size];
      
          if (getpwnam_r(user.get().c_str(), &passwd, buffer, size, &result) == 0) {
            ... 
            delete[] buffer;
            return gid;
          } else {
            // RHEL7 (and possibly other systems) will return non-zero and
            // set one of the following errors for "The given name or uid
            // was not found." See 'man getpwnam_r'. We only check for the
            // errors explicitly listed, and do not consider the ellipsis.
            if (errno == ENOENT ||
                errno == ESRCH ||
                errno == EBADF ||
                errno == EPERM) {
              return None();
             // HERE WE DO NOT DELETE BUFFER.
            }
           ...
           // getpwnam_r set ERANGE so try again with a larger buffer.
            size *= 2;
            delete[] buffer;
         }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                js84 Jörg Schad
                Reporter:
                js84 Jörg Schad
                Shepherd:
                Till Toenshoff
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: