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

How can someone just add a FIXME for such a simple case?!
This commit is contained in:
Beat Küng 2016-04-16 10:25:23 +02:00 committed by tumbili
parent fdc10d212b
commit 80e05dd3a3
2 changed files with 12 additions and 5 deletions

View File

@ -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;
}

View File

@ -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;
}