Bug Summary

File:daq/expreco/src/EventServer.cc
Warning:line 77, column 10
Potential leak of memory pointed to by 'evtbuffer'

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 EventServer.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/expreco/src/EventServer.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/expreco/EventServer.h"
10#include <framework/pcore/MsgHandler.h>
11
12#include <unistd.h>
13
14using namespace Belle2;
15using namespace std;
16
17// constructor/destructor
18
19EventServer::EventServer(string rbufname, int port) : m_port(port)
20{
21 // Attach to RingBuffer
22 m_rbuf = new RingBuffer(rbufname.c_str());
23
24 // Open EvtSocket
25 m_sock = new EvtSocketRecv(m_port, false);
26 m_man = new EvtSocketManager(m_sock);
27}
28
29EventServer::~EventServer()
30{
31 delete m_rbuf;
32 delete m_sock;
33 delete m_man;
34}
35
36int EventServer::server()
37{
38 SocketIO sio;
39 MsgHandler msghdl(0);
40 char* evtbuffer = new char[MAXEVTSIZE80000000];
1
Memory is allocated
41
42 // vector<int> recvsock;
43 int loop_counter [[maybe_unused]] = 0;
44 while (m_force_exit == 0) {
2
Assuming field 'm_force_exit' is not equal to 0
3
Loop condition is false. Execution jumps to the end of the function
45 // Pick up a event from RingBuffer (non blocking)
46 int size = m_rbuf->remq((int*)evtbuffer);
47 // if ( size > 0 )
48 // printf ( "From RB : event size = %d\n", size );
49
50 // Check connection request
51 int exam_stat = m_man->examine();
52 // printf("Examine: exam_stat = %d\n", exam_stat);
53 if (exam_stat == 0) {
54 printf("Initial connection request detected!\n");
55 // int fd = recvsock[;
56 } else if (exam_stat == 1 && size > 0) { //
57 // printf ( "Event data data ready on socket\n" );
58 vector<int>& recvsock = m_man->connected_socket_list();
59 // printf ( "size of recvsock = %d\n", recvsock.size() );
60 for (vector<int>::iterator it = recvsock.begin();
61 it != recvsock.end(); ++it) {
62 int fd = *it;
63 if (m_man->connected(fd, true)) {
64 int is = sio.put(fd, evtbuffer, size * 4);
65 // printf ( "data put on socket : %d\n", is );
66 if (is <= 0) {
67 printf("EventServer: fd %d disconnected\n", fd);
68 m_man->remove(fd);
69 break;
70 }
71 }
72 }
73 }
74 usleep(1000);
75 loop_counter++;
76 }
77 return 0;
4
Potential leak of memory pointed to by 'evtbuffer'
78}
79