Skip to content

Commit

Permalink
src/systemcmds/uorb: Map every uorb instance just once
Browse files Browse the repository at this point in the history
Fix a memory leak in uorb systemcmd

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Jan 30, 2024
1 parent e4d469a commit ff81016
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/systemcmds/uorb/uORBDeviceMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,33 @@ int uORB::DeviceMaster::addNewDeviceNodes(DeviceNodeStatisticsData **first_node,
DIR *shm_dir = opendir(CONFIG_FS_SHMFS_VFS_PATH);
struct dirent *shm;
const char orb_name_prefix[] = "_orb_";
char orb_name[orb_maxpath];

while ((shm = readdir(shm_dir)) != nullptr) {

if (strncmp(orb_name_prefix, shm->d_name, sizeof(orb_name_prefix) - 1)) {
continue;
}

// check if already added
cur_node = *first_node;

while (cur_node) {
int instance = cur_node->node->get_instance();

if (uORB::Utils::node_mkpath(orb_name, cur_node->node->get_meta(), &instance)) {
PX4_ERR("Can't construct orb name?");
continue;
}

if (!strcmp(orb_name, shm->d_name)) {
// already added
continue;
}

cur_node = cur_node->next;
}

void *ptr = nullptr;
uORB::DeviceNode *node = nullptr;

Expand All @@ -139,19 +159,6 @@ int uORB::DeviceMaster::addNewDeviceNodes(DeviceNodeStatisticsData **first_node,

++num_topics;

//check if already added
cur_node = *first_node;

while (cur_node && cur_node->node != node) {
cur_node = cur_node->next;
}

if (cur_node) {
// currently nuttx creates a new mapping on every mmap. TODO: check linux
px4_munmap(node, sizeof(uORB::DeviceNode));
continue;
}

if (num_filters > 0 && topic_filter) {
bool matched = false;

Expand Down

0 comments on commit ff81016

Please sign in to comment.