Bug Summary

File:programs/Utilities/hddm_merge_files/Process_s.cc
Location:line 81, column 4
Description:Potential leak of memory pointed to by 'fout'

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_s.hpp>
8
9//-----------
10// Process_s -- HDDM simulation format
11//-----------
12void Process_s(unsigned int &NEvents, unsigned int &NEvents_read)
13{
14 // Output file
15 std::cout << " output file: " << OUTFILENAME << std::endl;
16 std::ofstream ofs(OUTFILENAME);
17 if (! ofs.is_open()) {
1
Taking false branch
18 std::cout << " Error opening output file \"" << OUTFILENAME
19 << "\"!" << std::endl;
20 exit(-1);
21 }
22 hddm_s::ostream *fout = new hddm_s::ostream(ofs);
2
Memory is allocated
23 if (HDDM_USE_COMPRESSION) {
3
Assuming 'HDDM_USE_COMPRESSION' is 0
4
Taking false branch
24 std::cout << " Enabling bz2 compression of output HDDM file stream"
25 << std::endl;
26 fout->setCompression(hddm_s::k_bz2_compression);
27 }
28 else {
29 std::cout << " HDDM compression disabled" << std::endl;
30 }
31 if (HDDM_USE_INTEGRITY_CHECKS) {
5
Assuming 'HDDM_USE_INTEGRITY_CHECKS' is 0
6
Taking false branch
32 std::cout << " Enabling CRC data integrity check in output HDDM"
33 " file stream" << std::endl;
34 fout->setIntegrityChecks(hddm_s::k_crc32_integrity);
35 }
36 else {
37 std::cout << " HDDM integrity checks disabled" << std::endl;
38 }
39
40 // Loop over input files
41 time_t last_time = time(NULL__null);
42 for (unsigned int i=0; i<INFILENAMES.size(); i++) {
7
Loop condition is false. Execution continues on line 81
43 std::cout << " input file: " << INFILENAMES[i] << std::endl;
44 std::ifstream ifs(INFILENAMES[i]);
45 if (! ifs.is_open()) {
46 std::cout << " Error opening input file \"" << INFILENAMES[i]
47 << "\"!" << std::endl;
48 exit(-1);
49 }
50 hddm_s::istream *fin = new hddm_s::istream(ifs);
51
52 // Loop over all events in input
53 while (ifs.good()) {
54 hddm_s::HDDM record;
55 *fin >> record;
56 NEvents_read++;
57
58 // Write this output event to file
59 *fout << record;
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
71 if (QUIT)
72 break;
73 }
74
75 // Close input file
76 ifs.close();
77 delete fin;
78 }
79
80 // Close output file
81 ofs.close();
8
Potential leak of memory pointed to by 'fout'
82}