[llvm] r358760 - llvm-undname: Attempt to fix leak-on-invalid found by oss-fuzz
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 19 07:13:12 PDT 2019
Author: nico
Date: Fri Apr 19 07:13:11 2019
New Revision: 358760
URL: http://llvm.org/viewvc/llvm-project?rev=358760&view=rev
Log:
llvm-undname: Attempt to fix leak-on-invalid found by oss-fuzz
Modified:
llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp
Modified: llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp?rev=358760&r1=358759&r2=358760&view=diff
==============================================================================
--- llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp (original)
+++ llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp Fri Apr 19 07:13:11 2019
@@ -1230,6 +1230,11 @@ Demangler::demangleStringLiteral(StringV
EncodedStringLiteralNode *Result = Arena.alloc<EncodedStringLiteralNode>();
+ // Must happen before the first `goto StringLiteralError`.
+ if (!initializeOutputStream(nullptr, nullptr, OS, 1024))
+ // FIXME: Propagate out-of-memory as an error?
+ std::terminate();
+
// Prefix indicating the beginning of a string literal
if (!MangledName.consumeFront("@_"))
goto StringLiteralError;
@@ -1261,9 +1266,6 @@ Demangler::demangleStringLiteral(StringV
if (MangledName.empty())
goto StringLiteralError;
- if (!initializeOutputStream(nullptr, nullptr, OS, 1024))
- // FIXME: Propagate out-of-memory as an error?
- std::terminate();
if (IsWcharT) {
Result->Char = CharKind::Wchar;
if (StringByteSize > 64)
@@ -1328,6 +1330,7 @@ Demangler::demangleStringLiteral(StringV
StringLiteralError:
Error = true;
+ std::free(OS.getBuffer());
return nullptr;
}
More information about the llvm-commits
mailing list