Bug Summary

File:daq/storage/modules/src/SeqRootMergerModule.cc
Warning:line 55, column 36
Potential leak of memory pointed to by 'evtbuf'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name SeqRootMergerModule.cc -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 -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="daq" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ daq/storage/modules/src/SeqRootMergerModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <daq/storage/modules/SeqRootMergerModule.h>
10
11#include <framework/core/Environment.h>
12
13#include <cstdlib>
14#include <cstdio>
15#include <fcntl.h>
16
17using namespace Belle2;
18
19//-----------------------------------------------------------------
20// Register the Module
21//-----------------------------------------------------------------
22REG_MODULE(SeqRootMerger)namespace { struct ModuleProxySeqRootMerger: public ModuleProxyBase
{ ModuleProxySeqRootMerger(): ModuleProxyBase("SeqRootMerger"
, "" "daq") {} virtual ::Belle2::Module* createInstance() const
override final { return new SeqRootMergerModule(); } } proxySeqRootMergerModule
; }
;
23
24//-----------------------------------------------------------------
25// Implementation
26//-----------------------------------------------------------------
27
28SeqRootMergerModule::SeqRootMergerModule() : Module()
29{
30 B2INFO("SeqRootMerger: Constructor done.")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "daq")) { { LogVariableStream varStream
; varStream << "SeqRootMerger: Constructor done."; Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Info, std::move(varStream), "daq", __PRETTY_FUNCTION__
, "daq/storage/modules/src/SeqRootMergerModule.cc", 30, 0)); }
; } } while(false)
;
31}
32
33
34SeqRootMergerModule::~SeqRootMergerModule()
35{
36
37}
38
39void SeqRootMergerModule::initialize()
40{
41 const std::vector<std::string>& inputFiles = Environment::Instance().getInputFilesOverride();
42 for (size_t i = 0; i < inputFiles.size(); i++) {
43 m_file.push_back(new SeqFile(inputFiles[i].c_str(), "r"));
44 }
45 m_streamer = new DataStoreStreamer();
46 readFile();
47}
48
49int SeqRootMergerModule::readFile()
50{
51 B2INFO("SeqRootMerger: initialize() started.")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "daq")) { { LogVariableStream varStream
; varStream << "SeqRootMerger: initialize() started."; Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Info, std::move(varStream), "daq", __PRETTY_FUNCTION__
, "daq/storage/modules/src/SeqRootMergerModule.cc", 51, 0)); }
; } } while(false)
;
2
Taking false branch
3
Loop condition is false. Exiting loop
52
53 char* evtbuf = new char[EvtMessage::c_MaxEventSize];
4
Memory is allocated
54 while (true) {
5
Loop condition is true. Entering loop body
55 if (m_file.size() == 0) return 0;
6
Assuming the condition is true
7
Taking true branch
8
Potential leak of memory pointed to by 'evtbuf'
56 int i = rand() % m_file.size();
57 int size = m_file[i]->read(evtbuf, EvtMessage::c_MaxEventSize);
58 if (size > 0) {
59 EvtMessage* evtmsg = new EvtMessage(evtbuf);
60 m_streamer->restoreDataStore(evtmsg);
61 if (evtmsg->type() == MSG_STREAMERINFO) {
62 B2INFO("Reading StreamerInfo")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "daq")) { { LogVariableStream varStream
; varStream << "Reading StreamerInfo"; Belle2::LogSystem
::Instance().sendMessage(Belle2::LogMessage(Belle2::LogConfig
::c_Info, std::move(varStream), "daq", __PRETTY_FUNCTION__, "daq/storage/modules/src/SeqRootMergerModule.cc"
, 62, 0)); }; } } while(false)
;
63 delete evtmsg;
64 } else {
65 delete evtmsg;
66 break;
67 }
68 } else {
69 m_file.erase(m_file.begin() + i);
70 }
71 }
72 delete [] evtbuf;
73
74 return m_file.size();
75}
76
77void SeqRootMergerModule::event()
78{
79 readFile();
1
Calling 'SeqRootMergerModule::readFile'
80}
81
82void SeqRootMergerModule::beginRun()
83{
84 B2INFO("SeqRootMerger: beginRun called.")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "daq")) { { LogVariableStream varStream
; varStream << "SeqRootMerger: beginRun called."; Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Info, std::move(varStream), "daq", __PRETTY_FUNCTION__
, "daq/storage/modules/src/SeqRootMergerModule.cc", 84, 0)); }
; } } while(false)
;
85}
86
87void SeqRootMergerModule::endRun()
88{
89 B2INFO("SeqRootMerger: endRun done.")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "daq")) { { LogVariableStream varStream
; varStream << "SeqRootMerger: endRun done."; Belle2::LogSystem
::Instance().sendMessage(Belle2::LogMessage(Belle2::LogConfig
::c_Info, std::move(varStream), "daq", __PRETTY_FUNCTION__, "daq/storage/modules/src/SeqRootMergerModule.cc"
, 89, 0)); }; } } while(false)
;
90}
91
92
93void SeqRootMergerModule::terminate()
94{
95 B2INFO("SeqRootMerger: terminate called")do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2::
LogConfig::c_Info, 0, "daq")) { { LogVariableStream varStream
; varStream << "SeqRootMerger: terminate called"; Belle2
::LogSystem::Instance().sendMessage(Belle2::LogMessage(Belle2
::LogConfig::c_Info, std::move(varStream), "daq", __PRETTY_FUNCTION__
, "daq/storage/modules/src/SeqRootMergerModule.cc", 95, 0)); }
; } } while(false)
;
96}
97
98