From 80e05dd3a329e7c8b4ba45f14aaa25befa53cf65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 16 Apr 2016 10:25:23 +0200 Subject: [PATCH] orb: fix memory leaks, forgotten unlock & wrong exit condition in advertisement How can someone just add a FIXME for such a simple case?! --- src/modules/uORB/uORBDevices_nuttx.cpp | 7 ++++++- src/modules/uORB/uORBDevices_posix.cpp | 10 ++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/uORB/uORBDevices_nuttx.cpp b/src/modules/uORB/uORBDevices_nuttx.cpp index dff43f7d12..994f16e1ac 100644 --- a/src/modules/uORB/uORBDevices_nuttx.cpp +++ b/src/modules/uORB/uORBDevices_nuttx.cpp @@ -611,6 +611,7 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg) objname = strdup(meta->o_name); if (objname == nullptr) { + unlock(); return -ENOMEM; } @@ -618,6 +619,8 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg) devpath = strdup(nodepath); if (devpath == nullptr) { + unlock(); + free((void *)objname); return -ENOMEM; } @@ -627,6 +630,8 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg) /* if we didn't get a device, that's bad */ if (node == nullptr) { unlock(); + free((void *)objname); + free((void *)devpath); return -ENOMEM; } @@ -664,7 +669,7 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg) } while (ret != OK && (group_tries < max_group_tries)); - if (group_tries > max_group_tries) { + if (ret != PX4_OK && group_tries >= max_group_tries) { ret = -ENOMEM; } diff --git a/src/modules/uORB/uORBDevices_posix.cpp b/src/modules/uORB/uORBDevices_posix.cpp index 0d19d10cf5..6d2d8d027b 100644 --- a/src/modules/uORB/uORBDevices_posix.cpp +++ b/src/modules/uORB/uORBDevices_posix.cpp @@ -617,6 +617,7 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) objname = strdup(meta->o_name); if (objname == nullptr) { + unlock(); return -ENOMEM; } @@ -624,7 +625,8 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) devpath = strdup(nodepath); if (devpath == nullptr) { - // FIXME - looks like we leaked memory here for objname + unlock(); + free((void *)objname); return -ENOMEM; } @@ -634,8 +636,8 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) /* if we didn't get a device, that's bad */ if (node == nullptr) { unlock(); - - // FIXME - looks like we leaked memory here for devpath and objname + free((void *)objname); + free((void *)devpath); return -ENOMEM; } @@ -674,7 +676,7 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) } while (ret != PX4_OK && (group_tries < max_group_tries)); - if (group_tries > max_group_tries) { + if (ret != PX4_OK && group_tries >= max_group_tries) { ret = -ENOMEM; }