Browse Source

orb: fix memory leaks, forgotten unlock & wrong exit condition in advertisement

How can someone just add a FIXME for such a simple case?!
sbg
Beat Küng 9 years ago committed by tumbili
parent
commit
80e05dd3a3
  1. 7
      src/modules/uORB/uORBDevices_nuttx.cpp
  2. 10
      src/modules/uORB/uORBDevices_posix.cpp

7
src/modules/uORB/uORBDevices_nuttx.cpp

@ -611,6 +611,7 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg) @@ -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) @@ -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) @@ -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) @@ -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;
}

10
src/modules/uORB/uORBDevices_posix.cpp

@ -617,6 +617,7 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) @@ -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) @@ -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) @@ -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) @@ -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;
}

Loading…
Cancel
Save