fix to access to shared memory that doesnt exist (#638)

* fix to access to shared memory that doesnt exist

* fix for freeing shm and then setting hostname from API

* exception error message moved to private function

* refactoring to avoid allocating intermediate string
This commit is contained in:
Dhanya Thattil
2023-02-13 11:29:54 +01:00
committed by GitHub
parent 18136fed9d
commit 5c8c3ae3f3
2 changed files with 23 additions and 7 deletions
+5 -4
View File
@@ -253,14 +253,15 @@ void DetectorImpl::setVirtualDetectorServers(const int numdet, const int port) {
}
void DetectorImpl::setHostname(const std::vector<std::string> &name) {
// this check is there only to allow the previous detsizechan command
if (shm()->totalNumberOfModules != 0) {
// do not free always to allow the previous detsize/ initialchecks command
if (shm.exists() && shm()->totalNumberOfModules != 0) {
LOG(logWARNING) << "There are already module(s) in shared memory."
"Freeing Shared memory now.";
bool initialChecks = shm()->initialChecks;
freeSharedMemory();
}
// could be called after freeing shm from API
if (!shm.exists()) {
setupDetector();
shm()->initialChecks = initialChecks;
}
for (const auto &hostname : name) {
addModule(hostname);