xiaoxiang781216 commented on code in PR #16356:
URL: https://github.com/apache/nuttx/pull/16356#discussion_r2084627419


##########
drivers/misc/optee.c:
##########
@@ -529,10 +534,21 @@ static int optee_close(FAR struct file *filep)
 {
   FAR struct optee_priv_data *priv = filep->f_priv;
   FAR struct optee_shm *shm;
+  FAR struct file *shm_filep;
   int id = 0;
 
   idr_for_each_entry(priv->shms, shm, id)
     {
+      if (shm->fd > -1 && fs_getfilep(shm->fd, &shm_filep) >= 0)
+        {
+          /* The user did not call close(), prevent vfs auto-close from
+           * double-freeing our SHM
+           */
+
+          shm_filep->f_priv = NULL;

Review Comment:
   > > but how to free in optee_shm_close if we zero out f_priv here?
   > 
   > We don’t. In this case the freeing of shm happens here, and `close(shmfd)` 
only frees the file descriptor. `f_priv` is set to NULL here so we don’t 
double-free the shm during `close(shmfd)`.
   > 
   
   how optee_shm_free free the resource if shm_filep->f_priv is zeroed here?
   if 
https://github.com/apache/nuttx/pull/16356/files#diff-57532e6c95da3890ba5255d39b9a830f8a31437d9ed15a610ecd2041991d7c8cR1262
 always return directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to