Closed Bug 2093682 Opened 7 days ago Closed 6 days ago

gtest ScopedUniqueDirectory leaks its directory in NDEBUG builds (rmdir inside assert)

Categories

(NSS :: Test, defect)

defect

Tracking

(nss 3.134)

RESOLVED FIXED
Tracking Status
nss --- 3.134

People

(Reporter: olav, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 external file)

~ScopedUniqueDirectory() calls rmdir() inside assert() (gtests/common/util.h:81), so builds with NDEBUG (--opt) never remove the directory. Since rand() is unseeded (bug 1879463), the next run in the same working directory tries the same names and finds them all taken. In opt builds the assert at line 65 is compiled out as well, so the test continues with an empty path and segfaults. This may be one of the "multiple ways" mentioned in bug 1879463 comment 4.

Steps to reproduce: build with ./build.sh --opt and run softoken_gtest twice in the same cwd. Run 1 passes and leaves 146 directories behind; run 2 fails and segfaults.

Fix: move the call out of the assert:

~ScopedUniqueDirectory() {
  int rv = rmdir(mPath.c_str());
  assert(rv == 0);
  (void)rv;
}

I'll attach a patch.

Deliberately left out (pre-existing, not needed for this fix; happy to add if wanted):

  • A failed rmdir in NDEBUG builds is still not reported; debug builds abort without path/errno.
  • The class is copyable; a copy would rmdir the same path twice.
  • If the constructor fails (empty mPath, assert compiled out), the destructor calls rmdir("").
  • NSS_GTEST_WORKDIR is joined without a path separator.

Pushed by jschanck@mozilla.com:
https://hg.mozilla.org/projects/nss/rev/467bb9910791
Don't call rmdir inside assert in ScopedUniqueDirectory. r=nss-reviewers,jschanck

Status: NEW → RESOLVED
Closed: 6 days ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: