Bug Summary

File:programs/Utilities/hddm_merge_files/Process_r.cc
Location:line 44, column 49
Description:Potential leak of memory pointed to by 'istr'

Annotated Source Code

1// $Id$
2//
3// Created Oct 25, 2013 Kei Moriya
4
5#include "hddm_merge_files.h"
6
7#include <HDDM/hddm_r.hpp>
8using namespace hddm_r;
9
10
11//-----------
12// Process_r -- HDDM REST format
13//-----------
14void Process_r(unsigned int &NEvents, unsigned int &NEvents_read)
15{
16 // Output file
17 std::cout << " output file: " << OUTFILENAME << std::endl;
18 std::ofstream ofs(OUTFILENAME);
19 if (! ofs.is_open()) {
1
Taking false branch
20 std::cout << " Error opening output file \"" << OUTFILENAME
21 << "\"!" << std::endl;
22 exit(-1);
23 }
24 hddm_r::ostream *ostr = new hddm_r::ostream(ofs);
25 if (HDDM_USE_COMPRESSION) {
2
Assuming 'HDDM_USE_COMPRESSION' is 0
3
Taking false branch
26 std::cout << " Enabling bz2 compression of output HDDM file stream"
27 << std::endl;
28 ostr->setCompression(hddm_r::k_bz2_compression);
29 }
30 else {
31 std::cout << " HDDM compression disabled" << std::endl;
32 }
33 if (HDDM_USE_INTEGRITY_CHECKS) {
4
Assuming 'HDDM_USE_INTEGRITY_CHECKS' is 0
5
Taking false branch
34 std::cout << " Enabling CRC data integrity check in output HDDM"
35 " file stream" << std::endl;
36 ostr->setIntegrityChecks(hddm_r::k_crc32_integrity);
37 }
38 else {
39 std::cout << " HDDM integrity checks disabled" << std::endl;
40 }
41
42 // Loop over input files
43 time_t last_time = time(NULL__null);
44 for (unsigned int i=0; i<INFILENAMES.size(); i++) {
6
Loop condition is true. Entering loop body
9
Potential leak of memory pointed to by 'istr'
45 std::cout << " input file: " << INFILENAMES[i] << std::endl;
46
47 // Open hddm file for reading
48 std::ifstream ifs(INFILENAMES[i]);
49
50 // Associate input file stream with HDDM record
51 hddm_r::istream *istr = new hddm_r::istream(ifs);
7
Memory is allocated
52
53 // Loop over events
54 while (ifs.good()) {
8
Loop condition is false. Execution continues on line 220
55 HDDM xrec;
56 *istr >> xrec;
57 NEvents_read++;
58
59 *ostr << xrec;
60 NEvents++;
61
62 // Update ticker
63 time_t now = time(NULL__null);
64 if (now != last_time) {
65 std::cout << " " << NEvents_read << " events read ("
66 << NEvents << " event written) \r";
67 std::cout.flush();
68 last_time = now;
69 }
70 if (QUIT)
71 break;
72 }
73 }
74}