mqueue/mq_close : Close the mq when mqdes is in one's group
If mqdes is not in one's group, we should not desclose the mq and release the mq_inode.
int mq_close_group(mqd_t mqdes, FAR struct task_group_s *group)
{
+ int ret = OK;
FAR struct mqueue_inode_s *msgq;
FAR struct inode *inode;
+ mqd_t mqdes_ptr;
DEBUGASSERT(mqdes != NULL && group != NULL);
@@ -102,6 +104,18 @@ int mq_close_group(mqd_t mqdes, FAR struct task_group_s *group)
if (mqdes) {
sched_lock();
+ /* Check that mqdes is in one's group */
+ mqdes_ptr = (mqd_t)sq_peek(&group->tg_msgdesq);
+ while (mqdes_ptr) {
+ if (mqdes_ptr == mqdes) {
+ break;
+ }
+ mqdes_ptr = (mqd_t)sq_next(mqdes_ptr);
+ }
+
+ /* If there is no mqdes in one's group, skip to desclose and inode release. */
+ if (mqdes_ptr != NULL) {
+
/* Find the message queue associated with the message descriptor */
msgq = mqdes->msgq;
@@ -119,10 +133,13 @@ int mq_close_group(mqd_t mqdes, FAR struct task_group_s *group)
/* Decrement the reference count on the inode, possibly freeing it */
mq_inode_release(inode);
+ } else {
+ ret = ERROR;
+ }
sched_unlock();
}
- return OK;
+ return ret;
}
/****************************************************************************
