Skip to content

Commit ef5089a

Browse files
authored
CN3BaseFileAccess: Release() when a file fails to load (#808)
This ensures that it isn't in a failed state, which can happen due to exceptions being thrown.
1 parent 4481584 commit ef5089a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/N3Base/N3BaseFileAccess.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ bool CN3BaseFileAccess::LoadFromFile()
109109

110110
try
111111
{
112-
return LoadSupportedVersions(file);
112+
if (LoadSupportedVersions(file))
113+
return true;
113114
}
114115
catch (const std::exception& ex)
115116
{
@@ -122,6 +123,9 @@ bool CN3BaseFileAccess::LoadFromFile()
122123
#endif
123124
}
124125

126+
// File failed to load. To avoid it being in an unexpected inconsistent state,
127+
// we should release it.
128+
Release();
125129
return false;
126130
}
127131

src/Server/shared-server/SharedMemoryBlock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ char* SharedMemoryBlock::Open(const std::string& name)
7474
catch (const interprocess_exception& ex)
7575
{
7676
if (ex.get_error_code() != not_found_error)
77+
{
7778
spdlog::error("SharedMemoryBlock::Open: failed to open existing shared memory block. "
7879
"name='{}' ex={}",
7980
name, ex.what());
81+
}
8082
}
8183

8284
return nullptr;

0 commit comments

Comments
 (0)