Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name InterpState.cpp -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 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/source/build-llvm -resource-dir /usr/lib/llvm-17/lib/clang/17 -I tools/clang/lib/AST -I /build/source/clang/lib/AST -I /build/source/clang/include -I tools/clang/include -I include -I /build/source/llvm/include -D _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-17/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/source/build-llvm=build-llvm -fmacro-prefix-map=/build/source/= -fcoverage-prefix-map=/build/source/build-llvm=build-llvm -fcoverage-prefix-map=/build/source/= -O3 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/source/build-llvm -fdebug-prefix-map=/build/source/build-llvm=build-llvm -fdebug-prefix-map=/build/source/= -fdebug-prefix-map=/build/source/build-llvm=build-llvm -fdebug-prefix-map=/build/source/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2023-05-10-133810-16478-1 -x c++ /build/source/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 "InterpFrame.h"
11#include "InterpStack.h"
12#include "Program.h"
13#include "State.h"
14
15using namespace clang;
16using namespace clang::interp;
17
18InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
19 Context &Ctx, SourceMapper *M)
20 : Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), Current(nullptr),
21 CallStackDepth(Parent.getCallStackDepth() + 1) {}
22
23InterpState::~InterpState() {
24 while (Current) {
25 InterpFrame *Next = Current->Caller;
26 delete Current;
27 Current = Next;
28 }
29
30 while (DeadBlocks) {
31 DeadBlock *Next = DeadBlocks->Next;
32 free(DeadBlocks);
33 DeadBlocks = Next;
34 }
35}
36
37Frame *InterpState::getCurrentFrame() {
38 if (Current && Current->Caller)
39 return Current;
40 return Parent.getCurrentFrame();
41}
42
43bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) {
44 QualType Type = E->getType();
45 CCEDiag(E, diag::note_constexpr_overflow) << Value << Type;
46 return noteUndefinedBehavior();
47}
48
49void InterpState::deallocate(Block *B) {
50 Descriptor *Desc = B->getDescriptor();
51 if (B->hasPointers()) {
1
Assuming the condition is true
2
Taking true branch
52 size_t Size = B->getSize();
53
54 // Allocate a new block, transferring over pointers.
55 char *Memory = reinterpret_cast<char *>(malloc(sizeof(DeadBlock) + Size));
3
Memory is allocated
56 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
57
58 // Move data from one block to another.
59 if (Desc->MoveFn)
4
Assuming field 'MoveFn' is null
5
Taking false branch
60 Desc->MoveFn(B, B->data(), D->data(), Desc);
61 } else {
62 // Free storage, if necessary.
63 if (Desc->DtorFn)
64 Desc->DtorFn(B, B->data(), Desc);
65 }
66}
6
Potential leak of memory pointed to by 'D'