pussuw commented on code in PR #9030: URL: https://github.com/apache/nuttx/pull/9030#discussion_r1169739708
########## sched/addrenv/addrenv.c: ########## @@ -237,62 +208,48 @@ int addrenv_switch(FAR struct tcb_s *tcb) * Allocate an address environment for a new process. * * Input Parameters: - * tcb - The tcb of the newly created task. - * ttype - The type of the task. + * None * * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. + * Pointer to the new address environment, or NULL if out of memory. * ****************************************************************************/ -int addrenv_allocate(FAR struct tcb_s *tcb, uint8_t ttype) +FAR struct addrenv_s *addrenv_allocate(void) { - int ret = OK; + FAR struct addrenv_s *addrenv; - if ((ttype & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL) + addrenv = (FAR struct addrenv_s *)kmm_zalloc(sizeof(struct addrenv_s)); + if (addrenv) { - tcb->addrenv_own = NULL; - } - else - { - tcb->addrenv_own = (FAR struct addrenv_s *) - kmm_zalloc(sizeof(struct addrenv_s)); - if (tcb->addrenv_own == NULL) - { - ret = -ENOMEM; - } + /* Take reference so this won't get freed */ + + addrenv->refs = 1; } - return ret; + return addrenv; } /**************************************************************************** * Name: addrenv_free * * Description: - * Free an address environment for a process. + * Unconditionally free an address environment. * * Input Parameters: * tcb - The tcb of the task. * * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. + * None * ****************************************************************************/ -int addrenv_free(FAR struct tcb_s *tcb) +void addrenv_free(FAR struct addrenv_s *addrenv) { - if (tcb->addrenv_own != NULL) + if (addrenv) { - kmm_free(tcb->addrenv_own); - tcb->addrenv_own = NULL; Review Comment: addrenv_own is not set for any TCB when this is called, so no need to clear it. The addrenv is attached after addrenv_attach() is called, and after that addrevn_free() must NOT be called, addrenv_drop() should be used instead. -- 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