From: Nico Weber Date: Fri, 19 Apr 2019 14:13:11 +0000 (+0000) Subject: llvm-undname: Attempt to fix leak-on-invalid found by oss-fuzz X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a946515b894d19663b34bb51d48a0ba8f97312c;p=llvm llvm-undname: Attempt to fix leak-on-invalid found by oss-fuzz git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358760 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Demangle/MicrosoftDemangle.cpp b/lib/Demangle/MicrosoftDemangle.cpp index 3fb8e0ec5c5..ebe2ef5de09 100644 --- a/lib/Demangle/MicrosoftDemangle.cpp +++ b/lib/Demangle/MicrosoftDemangle.cpp @@ -1230,6 +1230,11 @@ Demangler::demangleStringLiteral(StringView &MangledName) { EncodedStringLiteralNode *Result = Arena.alloc(); + // 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(StringView &MangledName) { 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(StringView &MangledName) { StringLiteralError: Error = true; + std::free(OS.getBuffer()); return nullptr; }