From: Kostya Serebryany Date: Wed, 12 Aug 2015 00:55:09 +0000 (+0000) Subject: [libFuzzer] use raw C IO to reduce the risk of a deadlock in a signal handler. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=75a267446622d836ee7f860d01ebbde94dae0def [libFuzzer] use raw C IO to reduce the risk of a deadlock in a signal handler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244707 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Fuzzer/FuzzerIO.cpp b/lib/Fuzzer/FuzzerIO.cpp index 1d25389770f..f0295e9a730 100644 --- a/lib/Fuzzer/FuzzerIO.cpp +++ b/lib/Fuzzer/FuzzerIO.cpp @@ -66,8 +66,11 @@ void CopyFileToErr(const std::string &Path) { } void WriteToFile(const Unit &U, const std::string &Path) { - std::ofstream OF(Path); - OF.write((const char*)U.data(), U.size()); + // Use raw C interface because this function may be called from a sig handler. + FILE *Out = fopen(Path.c_str(), "w"); + if (!Out) return; + fwrite(U.data(), sizeof(U[0]), U.size(), Out); + fclose(Out); } void ReadDirToVectorOfUnits(const char *Path, std::vector *V,