Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions modules/tbl/fsw/src/cfe_tbl_task_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ CFE_Status_t CFE_TBL_LoadCmd(const CFE_TBL_LoadCmd_t *data)
Status = CFE_TBL_TxnOpenTableLoadFile(&Txn, LoadFilename, &FileDescriptor, &Header);
if (Status == CFE_SUCCESS)
{
/* NOTE: the FileDescriptor is valid and must be closed before leaving this block */

/* Locate specified table in registry (wrapped in a lock) */
/* NOTE: The header reading code ensures null term on the table name string, so its OK to pass direct */
CFE_TBL_TxnLockRegistry(&Txn);
Expand All @@ -430,17 +432,20 @@ CFE_Status_t CFE_TBL_LoadCmd(const CFE_TBL_LoadCmd_t *data)
}

CFE_TBL_TxnUnlockRegistry(&Txn);
}

if (Status == CFE_SUCCESS)
{
Status = CFE_TBL_ValidateFileIsLoadable(&Txn, &Header.Tbl);
}
if (Status == CFE_SUCCESS)
{
Status = CFE_TBL_ValidateFileIsLoadable(&Txn, &Header.Tbl);
}

if (Status == CFE_SUCCESS)
{
/* Read the file content into the working buffer */
Status = CFE_TBL_LoadContentFromFile(&Txn, FileDescriptor, Header.Tbl.Offset, Header.Tbl.NumBytes);
if (Status == CFE_SUCCESS)
{
/* Read the file content into the working buffer */
Status = CFE_TBL_LoadContentFromFile(&Txn, FileDescriptor, Header.Tbl.Offset, Header.Tbl.NumBytes);
}

/* Done with the file now -- must always close the file regardless of what happened */
OS_close(FileDescriptor);
}

/* If all the above worked out, then set the meta info in the load buffer */
Expand Down
6 changes: 6 additions & 0 deletions modules/tbl/ut-coverage/tbl_ut_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetDefaultReturnValue(UT_KEY(OS_OpenCreate), OS_ERROR);
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
/* Nothing was opened, so nothing is closed */
UtAssert_STUB_COUNT(OS_close, 0);

/* Test response to inability to find the table in the registry */
UT_InitData_TBL();
Expand All @@ -317,6 +319,8 @@ void Test_CFE_TBL_LoadCmd(void)
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandErrorCounter);
CFE_UtAssert_EVENTSENT(CFE_TBL_NO_SUCH_TABLE_ERR_EID);
/* The file was opened before the lookup failed and must not leak */
UtAssert_STUB_COUNT(OS_close, 1);

/* The rest of the tests will use registry 0, note empty name matches */
RegRec0Ptr->OwnerAppId = AppID;
Expand Down Expand Up @@ -362,6 +366,8 @@ void Test_CFE_TBL_LoadCmd(void)
UT_SetReadHeader(&StdFileHeader, sizeof(StdFileHeader));
UtAssert_INT32_EQ(CFE_TBL_LoadCmd(&LoadCmd), CFE_SUCCESS);
CFE_UtAssert_COUNTER_INCR(CFE_TBL_Global.CommandCounter);
/* A successful load closes its file exactly once */
UtAssert_STUB_COUNT(OS_close, 1);

/* Test with differing amount of data from header's claim */
UT_InitData_TBL();
Expand Down