summaryrefslogtreecommitdiffstats
path: root/tester/covoar/Explanations.cc
diff options
context:
space:
mode:
authorRyan Long <ryan.long@oarcorp.com>2021-05-17 13:06:51 -0400
committerJoel Sherrill <joel@rtems.org>2021-06-04 12:22:38 -0500
commit9f4887ccafa77d8c477e7a1d6995b6cbc3b20476 (patch)
treeeb8d2d98320d76eb960f2c959b6dc067255ba77f /tester/covoar/Explanations.cc
parentrtems-bsp-builder: Change to waf build system (diff)
downloadrtems-tools-9f4887ccafa77d8c477e7a1d6995b6cbc3b20476.tar.bz2
Explanations.cc: Fix resource leaks
CID 1399608: Resource leak in load(). CID 1399611: Resource leak in load(). Closes #4417
Diffstat (limited to 'tester/covoar/Explanations.cc')
-rw-r--r--tester/covoar/Explanations.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/tester/covoar/Explanations.cc b/tester/covoar/Explanations.cc
index 12bd809..d94cd2e 100644
--- a/tester/covoar/Explanations.cc
+++ b/tester/covoar/Explanations.cc
@@ -32,7 +32,7 @@ namespace Coverage {
#define MAX_LINE_LENGTH 512
FILE *explain;
char *cStatus;
- Explanation *e;
+ Explanation e;
int line = 1;
if (!explanations)
@@ -46,7 +46,6 @@ namespace Coverage {
}
while ( 1 ) {
- e = new Explanation;
// Read the starting line of this explanation and
// skip blank lines between
do {
@@ -65,12 +64,13 @@ namespace Coverage {
what << "line " << line
<< "contains a duplicate explanation ("
<< inputBuffer << ")";
+ fclose( explain );
throw rld::error( what, "Explanations::load" );
}
// Add the starting line and file
- e->startingPoint = std::string(inputBuffer);
- e->found = false;
+ e.startingPoint = std::string(inputBuffer);
+ e.found = false;
// Get the classification
cStatus = fgets( inputBuffer, MAX_LINE_LENGTH, explain );
@@ -78,10 +78,11 @@ namespace Coverage {
std::ostringstream what;
what << "line " << line
<< "out of sync at the classification";
+ fclose( explain );
throw rld::error( what, "Explanations::load" );
}
inputBuffer[ strlen(inputBuffer) - 1] = '\0';
- e->classification = inputBuffer;
+ e.classification = inputBuffer;
line++;
// Get the explanation
@@ -92,6 +93,7 @@ namespace Coverage {
std::ostringstream what;
what << "line " << line
<< "out of sync at the explanation";
+ fclose( explain );
throw rld::error( what, "Explanations::load" );
}
inputBuffer[ strlen(inputBuffer) - 1] = '\0';
@@ -102,15 +104,17 @@ namespace Coverage {
break;
}
// XXX only taking last line. Needs to be a vector
- e->explanation.push_back( inputBuffer );
+ e.explanation.push_back( inputBuffer );
}
// Add this to the set of Explanations
- set[ e->startingPoint ] = *e;
+ set[ e.startingPoint ] = e;
}
done:
;
+ fclose( explain );
+
#undef MAX_LINE_LENGTH
}