[llvm-bugs] [Bug 38835] New: AnnotateAttr leaks its annotations

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 4 21:53:29 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38835

            Bug ID: 38835
           Summary: AnnotateAttr leaks its annotations
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: mh+llvm at glandium.org
                CC: llvm-bugs at lists.llvm.org

The full generated code for AnnotateAttr is:

class AnnotateAttr : public InheritableParamAttr {
unsigned annotationLength;
char *annotation;
public:
  static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef
Annotation, SourceRange Loc = SourceRange()) {
    auto *A = new (Ctx) AnnotateAttr(Loc, Ctx, Annotation, 0);
    A->setImplicit(true);
    return A;
  }
  AnnotateAttr(SourceRange R, ASTContext &Ctx
              , llvm::StringRef Annotation
              , unsigned SI
             )
    : InheritableParamAttr(attr::Annotate, R, SI, false, false)
              , annotationLength(Annotation.size()),annotation(new (Ctx, 1)
char[annotationLength])
  {
      if (!Annotation.empty())
        std::memcpy(annotation, Annotation.data(), annotationLength);
  }
  AnnotateAttr *clone(ASTContext &C) const;
  void printPretty(raw_ostream &OS,
                   const PrintingPolicy &Policy) const;
  const char *getSpelling() const;
  llvm::StringRef getAnnotation() const {
    return llvm::StringRef(annotation, annotationLength);
  }
  unsigned getAnnotationLength() const {
    return annotationLength;
  }
  void setAnnotation(ASTContext &C, llvm::StringRef S) {
    annotationLength = S.size();
    this->annotation = new (C, 1) char [annotationLength];
    if (!S.empty())
      std::memcpy(this->annotation, S.data(), annotationLength);
  }
  static bool classof(const Attr *A) { return A->getKind() == attr::Annotate; }
};


Destruction of a AnnotateAttr will leak the `annotation` string. So does calls
to `setAnnotation`.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180905/7ce2efc0/attachment.html>


More information about the llvm-bugs mailing list