From 76144aaa6397fe9e16893882cf59c5c9c0684a66 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Thu, 19 Nov 2015 13:52:16 -0800 Subject: Change _stdio_handles_locking into _caller_handles_locking. It is reported by tsan that funlockfile() can unlock an unlocked mutex. It happens when printf() is called before fopen() or other stdio stuff. As FLOCKFILE(fp) is called before __sinit(), _stdio_handles_locking is false, and _FLOCK(fp) will not be locked. But then cantwrite(fp) in __vfprintf() calls__sinit(), which makes _stdio_handles_locking become true, and FUNLOCKFILE(fp) unlocks _FLOCK(fp). Change _stdio_handles_locking into _caller_handles_locking, so __sinit() won't change its value. Add test due to my previous fault. Bug: 25392375 Change-Id: I483e3c3cdb28da65e62f1fd9615bf58c5403b4dd --- libc/stdio/stdio_ext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libc/stdio/stdio_ext.cpp') diff --git a/libc/stdio/stdio_ext.cpp b/libc/stdio/stdio_ext.cpp index 310076a3a..f273d45fe 100644 --- a/libc/stdio/stdio_ext.cpp +++ b/libc/stdio/stdio_ext.cpp @@ -74,7 +74,7 @@ void _flushlbf() { } int __fsetlocking(FILE* fp, int type) { - int old_state = _EXT(fp)->_stdio_handles_locking ? FSETLOCKING_INTERNAL : FSETLOCKING_BYCALLER; + int old_state = _EXT(fp)->_caller_handles_locking ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL; if (type == FSETLOCKING_QUERY) { return old_state; } @@ -84,7 +84,7 @@ int __fsetlocking(FILE* fp, int type) { __libc_fatal("Bad type (%d) passed to __fsetlocking", type); } - _EXT(fp)->_stdio_handles_locking = (type == FSETLOCKING_INTERNAL); + _EXT(fp)->_caller_handles_locking = (type == FSETLOCKING_BYCALLER); return old_state; } -- cgit v1.2.3