[llvm] 1128311 - [AMDGPU][llvm-objdump] Fix memory leak in recent commit

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Sun May 2 12:28:26 PDT 2021


Could you use make_unique, rather than "unique_ptr u(new T())"?

On Mon, Apr 26, 2021 at 10:52 AM Tim Renouf via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> Author: Tim Renouf
> Date: 2021-04-26T18:50:21+01:00
> New Revision: 1128311a19179ceca799ff0fbc4dd206ab56e560
>
> URL:
> https://github.com/llvm/llvm-project/commit/1128311a19179ceca799ff0fbc4dd206ab56e560
> DIFF:
> https://github.com/llvm/llvm-project/commit/1128311a19179ceca799ff0fbc4dd206ab56e560.diff
>
> LOG: [AMDGPU][llvm-objdump] Fix memory leak in recent commit
>
> Hopefully stops sanitizer fail in AMDGPU llvm-objdump test.
>
> Change-Id: I7331151d1cb65292bd06b6ae283349fe7231cf6b
>
> Added:
>
>
> Modified:
>     llvm/tools/llvm-objdump/llvm-objdump.cpp
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp
> b/llvm/tools/llvm-objdump/llvm-objdump.cpp
> index 4b2ca6560677..2d5a7287204a 100644
> --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
> +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
> @@ -975,11 +975,11 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes,
> const MCInstrAnalysis *MIA,
>  // Create an MCSymbolizer for the target and add it to the MCDisassembler.
>  // This is currently only used on AMDGPU, and assumes the format of the
>  // void * argument passed to AMDGPU's createMCSymbolizer.
> -static void addSymbolizer(MCContext &Ctx, const Target *Target,
> -                          StringRef TripleName, MCDisassembler *DisAsm,
> -                          uint64_t SectionAddr, ArrayRef<uint8_t> Bytes,
> -                          SectionSymbolsTy &Symbols,
> -                          std::vector<std::string *>
> &SynthesizedLabelNames) {
> +static void addSymbolizer(
> +    MCContext &Ctx, const Target *Target, StringRef TripleName,
> +    MCDisassembler *DisAsm, uint64_t SectionAddr, ArrayRef<uint8_t> Bytes,
> +    SectionSymbolsTy &Symbols,
> +    std::vector<std::unique_ptr<std::string>> &SynthesizedLabelNames) {
>
>    std::unique_ptr<MCRelocationInfo> RelInfo(
>        Target->createMCRelocationInfo(TripleName, Ctx));
> @@ -1015,8 +1015,9 @@ static void addSymbolizer(MCContext &Ctx, const
> Target *Target,
>                      LabelAddrs.begin());
>    // Add the labels.
>    for (unsigned LabelNum = 0; LabelNum != LabelAddrs.size(); ++LabelNum) {
> -    SynthesizedLabelNames.push_back(
> -        new std::string((Twine("L") + Twine(LabelNum)).str()));
> +    std::unique_ptr<std::string> Name(new std::string);
> +    *Name = (Twine("L") + Twine(LabelNum)).str();
> +    SynthesizedLabelNames.push_back(std::move(Name));
>      Symbols.push_back(SymbolInfoTy(
>          LabelAddrs[LabelNum], *SynthesizedLabelNames.back(),
> ELF::STT_NOTYPE));
>    }
> @@ -1193,7 +1194,7 @@ static void disassembleObject(const Target
> *TheTarget, const ObjectFile *Obj,
>      ArrayRef<uint8_t> Bytes = arrayRefFromStringRef(
>          unwrapOrError(Section.getContents(), Obj->getFileName()));
>
> -    std::vector<std::string *> SynthesizedLabelNames;
> +    std::vector<std::unique_ptr<std::string>> SynthesizedLabelNames;
>      if (Obj->isELF() && Obj->getArch() == Triple::amdgcn) {
>        // AMDGPU disassembler uses symbolizer for printing labels
>        addSymbolizer(Ctx, TheTarget, TripleName, DisAsm, SectionAddr,
> Bytes,
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210502/96a3f671/attachment.html>


More information about the llvm-commits mailing list