Bug Summary

File:clang/lib/AST/Interp/InterpState.cpp
Warning:line 74, column 1
Potential leak of memory pointed to by 'D'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name InterpState.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -relaxed-aliasing -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -D CLANG_VENDOR="Debian " -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/build-llvm/tools/clang/lib/AST -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/clang/lib/AST -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/clang/include -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/build-llvm/include -I /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/llvm/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/build-llvm/tools/clang/lib/AST -fdebug-prefix-map=/build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -o /tmp/scan-build-2019-12-07-102640-14763-1 -x c++ /build/llvm-toolchain-snapshot-10~+201911111502510600c19528f1809/clang/lib/AST/Interp/InterpState.cpp
1//===--- InterpState.cpp - Interpreter for the constexpr VM -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "InterpState.h"
10#include <limits>
11#include "Function.h"
12#include "InterpFrame.h"
13#include "InterpStack.h"
14#include "Opcode.h"
15#include "PrimType.h"
16#include "Program.h"
17#include "State.h"
18
19using namespace clang;
20using namespace clang::interp;
21
22using APSInt = llvm::APSInt;
23
24InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
25 Context &Ctx, SourceMapper *M)
26 : Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), Current(nullptr),
27 CallStackDepth(Parent.getCallStackDepth() + 1) {}
28
29InterpState::~InterpState() {
30 while (Current) {
31 InterpFrame *Next = Current->Caller;
32 delete Current;
33 Current = Next;
34 }
35
36 while (DeadBlocks) {
37 DeadBlock *Next = DeadBlocks->Next;
38 free(DeadBlocks);
39 DeadBlocks = Next;
40 }
41}
42
43Frame *InterpState::getCurrentFrame() {
44 if (Current && Current->Caller) {
45 return Current;
46 } else {
47 return Parent.getCurrentFrame();
48 }
49}
50
51bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) {
52 QualType Type = E->getType();
53 CCEDiag(E, diag::note_constexpr_overflow) << Value << Type;
54 return noteUndefinedBehavior();
55}
56
57void InterpState::deallocate(Block *B) {
58 Descriptor *Desc = B->getDescriptor();
59 if (B->hasPointers()) {
1
Assuming the condition is true
2
Taking true branch
60 size_t Size = B->getSize();
61
62 // Allocate a new block, transferring over pointers.
63 char *Memory = reinterpret_cast<char *>(malloc(sizeof(DeadBlock) + Size));
3
Memory is allocated
64 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
65
66 // Move data from one block to another.
67 if (Desc->MoveFn
3.1
Field 'MoveFn' is null
)
4
Taking false branch
68 Desc->MoveFn(B, B->data(), D->data(), Desc);
69 } else {
70 // Free storage, if necessary.
71 if (Desc->DtorFn)
72 Desc->DtorFn(B, B->data(), Desc);
73 }
74}
5
Potential leak of memory pointed to by 'D'