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-19 11:12:36 +02:00
committed by tumbili
parent fdc10d212b
commit 80e05dd3a3
2 changed files with 12 additions and 5 deletions
+6 -1
View File
@@ -611,6 +611,7 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg)
objname = strdup(meta->o_name); objname = strdup(meta->o_name);
if (objname == nullptr) { if (objname == nullptr) {
unlock();
return -ENOMEM; return -ENOMEM;
} }
@@ -618,6 +619,8 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg)
devpath = strdup(nodepath); devpath = strdup(nodepath);
if (devpath == nullptr) { if (devpath == nullptr) {
unlock();
free((void *)objname);
return -ENOMEM; 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 we didn't get a device, that's bad */
if (node == nullptr) { if (node == nullptr) {
unlock(); unlock();
free((void *)objname);
free((void *)devpath);
return -ENOMEM; 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)); } 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; ret = -ENOMEM;
} }
+6 -4
View File
@@ -617,6 +617,7 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
objname = strdup(meta->o_name); objname = strdup(meta->o_name);
if (objname == nullptr) { if (objname == nullptr) {
unlock();
return -ENOMEM; return -ENOMEM;
} }
@@ -624,7 +625,8 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
devpath = strdup(nodepath); devpath = strdup(nodepath);
if (devpath == nullptr) { if (devpath == nullptr) {
// FIXME - looks like we leaked memory here for objname unlock();
free((void *)objname);
return -ENOMEM; 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 we didn't get a device, that's bad */
if (node == nullptr) { if (node == nullptr) {
unlock(); unlock();
free((void *)objname);
// FIXME - looks like we leaked memory here for devpath and objname free((void *)devpath);
return -ENOMEM; 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)); } 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; ret = -ENOMEM;
} }