[tsan] don't crash on closedir(0)

llvm-svn: 257223
This commit is contained in:
Kostya Serebryany 2016-01-08 22:48:19 +00:00
parent f7aeda1f07
commit abc2c998d2
2 changed files with 9 additions and 2 deletions

View File

@ -1892,8 +1892,10 @@ TSAN_INTERCEPTOR(int, rmdir, char *path) {
TSAN_INTERCEPTOR(int, closedir, void *dirp) {
SCOPED_TSAN_INTERCEPTOR(closedir, dirp);
int fd = dirfd(dirp);
FdClose(thr, pc, fd);
if (dirp) {
int fd = dirfd(dirp);
FdClose(thr, pc, fd);
}
return REAL(closedir)(dirp);
}

View File

@ -0,0 +1,5 @@
// Check that closedir(NULL) is ok.
// RUN: %clang -O2 %s -o %t && %run %t
#include <sys/types.h>
#include <dirent.h>
int main() { closedir(0); }