Skip to content

[Bug] C++ implementation has undefined behavior in destructor and is not cross-platform #236

@GaneshPatil7517

Description

@GaneshPatil7517

@pradeeban
Bug A: Destructor crashes when shared memory was never used

The destructor unconditionally calls shmdt() on pointers that are never initialized when file-based communication is used:
~Concore() {
shmdt(sharedData_create); // Uninitialized pointer if communication_oport == 0
shmdt(sharedData_get); // Uninitialized pointer if communication_iport == 0
shmctl(shmId_create, IPC_RMID, nullptr); // shmId_create is garbage
}

This is undefined behavior and will likely segfault on any file-based study.

Fix: Initialize pointers to nullptr and add guards:

~Concore() {
if (communication_oport == 1 && sharedData_create != nullptr) {
shmdt(sharedData_create);
shmctl(shmId_create, IPC_RMID, nullptr);
}
if (communication_iport == 1 && sharedData_get != nullptr) {
shmdt(sharedData_get);
}
}

Bug B: POSIX-only headers — won't compile on Windows
#include <sys/ipc.h> // POSIX only
#include <sys/shm.h> // POSIX only
#include <unistd.h> // POSIX only

README states Windows is supported, but concore.hpp cannot compile on Windows.

Bug C: mapParser() crashes on empty/missing port file (line ~176)
If port file is missing, portstr is empty → portstr[portstr.size()-1] accesses index -1 → undefined behavior.

Bug D: Constructor dereferences empty map iterators (line ~61-62)

std::map<std::string, int>::iterator it_iport = iport.begin();
int iport_number = ExtractNumeric(it_iport->first); // UB if iport is empty

Bug E: No retry limit in read_FM() and read_SM() — infinite loop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions