diff --git a/src/modules/uORB/ORBMap.hpp b/src/modules/uORB/ORBMap.hpp index 186c46ce18..cb44936fda 100644 --- a/src/modules/uORB/ORBMap.hpp +++ b/src/modules/uORB/ORBMap.hpp @@ -62,13 +62,19 @@ public: unlinkNext(_top); if (_top->next == nullptr) { - free((void *)_top->node_name); free(_top); _top = nullptr; _end = nullptr; } } } + + /** + * Insert an element with a unique name + * @param node_name name of the node. This will not be copied, so the caller has to ensure + * the pointer is valid until the node is removed from ORBMap + * @param node + */ void insert(const char *node_name, uORB::DeviceNode *node) { Node **p; @@ -90,7 +96,7 @@ public: } _end->next = nullptr; - _end->node_name = strdup(node_name); + _end->node_name = node_name; _end->node = node; } @@ -124,21 +130,6 @@ public: return nullptr; } - void unlinkNext(Node *a) - { - Node *b = a->next; - - if (b != nullptr) { - if (_end == b) { - _end = a; - } - - a->next = b->next; - free((void *)b->node_name); - free(b); - } - } - Node *top() const { return _top; @@ -150,6 +141,20 @@ public: } private: + void unlinkNext(Node *a) + { + Node *b = a->next; + + if (b != nullptr) { + if (_end == b) { + _end = a; + } + + a->next = b->next; + free(b); + } + } + Node *_top; Node *_end; }; diff --git a/src/modules/uORB/uORBDevices.cpp b/src/modules/uORB/uORBDevices.cpp index b03a2980a2..ed44d7a9c9 100644 --- a/src/modules/uORB/uORBDevices.cpp +++ b/src/modules/uORB/uORBDevices.cpp @@ -912,9 +912,9 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) } else { // add to the node map;. #ifdef __PX4_NUTTX - _node_map.insert(nodepath, node); + _node_map.insert(devpath, node); #else - _node_map[std::string(nodepath)] = node; + _node_map[std::string(devpath)] = node; #endif }