Skip to content

Commit 1b7c5f4

Browse files
Fix DpCatalog to properly close file in off-nominal conditions (#5098)
* Update DpCatalog.cpp fixed issue #5092 impromper file handing * Fix missing closes --------- Co-authored-by: M Starch <LeStarch@googlemail.com>
1 parent 34b5b5d commit 1b7c5f4

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Svc/DpCatalog/DpCatalog.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Fw::CmdResponse DpCatalog::loadStateFile() {
155155
stat = stateFile.read(buffer, size);
156156
if (stat != Os::File::OP_OK) {
157157
this->log_WARNING_HI_StateFileReadError(this->m_stateFile, stat, static_cast<I32>(fileLoc));
158+
stateFile.close();
158159
return Fw::CmdResponse::EXECUTION_ERROR;
159160
}
160161

@@ -169,6 +170,7 @@ Fw::CmdResponse DpCatalog::loadStateFile() {
169170
if (size != sizeof(buffer)) {
170171
this->log_WARNING_HI_StateFileTruncated(this->m_stateFile, static_cast<I32>(fileLoc),
171172
static_cast<I32>(size));
173+
stateFile.close();
172174
return Fw::CmdResponse::OK;
173175
}
174176

@@ -202,7 +204,7 @@ Fw::CmdResponse DpCatalog::loadStateFile() {
202204
fileLoc += size;
203205
this->m_stateFileEntries++;
204206
}
205-
207+
stateFile.close();
206208
return Fw::CmdResponse::OK;
207209
}
208210

@@ -265,6 +267,7 @@ void DpCatalog::pruneAndWriteStateFile() {
265267
stat = stateFile.write(buffer, size);
266268
if (stat != Os::File::OP_OK) {
267269
this->log_WARNING_HI_StateFileWriteError(this->m_stateFile, stat);
270+
stateFile.close();
268271
return;
269272
}
270273
}
@@ -308,6 +311,7 @@ void DpCatalog::appendFileState(const DpStateEntry& entry) {
308311
FwSizeType size = entryBuffer.getSize();
309312
stat = stateFile.write(buffer, size);
310313
if (stat != Os::File::OP_OK) {
314+
stateFile.close();
311315
this->log_WARNING_HI_StateFileWriteError(this->m_stateFile, stat);
312316
return;
313317
}

0 commit comments

Comments
 (0)