This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can_Pull() from RTL seems stange ...

Hi,

I noticed something strange in the CAN_receive function of the RTL ARM library.

When you look at the CAN_pull function, it returns a pointer CAN_Msg object , but that has just been deallocated at the end of the function !!!

So you can always used a object deallocated by the _free_box function ?

static CAN_ERROR CAN_pull (U32 ctrl, CAN_msg *msg, U16 timeout)  {
  CAN_msg *ptrmsg;
  U32 ctrl0 = ctrl-1;                 /* Controller index 0 .. x-1           */

  /* Wait for received message in mailbox                                    */
  if (os_mbx_wait (MBX_rx_ctrl[ctrl0], (void **)&ptrmsg, timeout) == OS_R_TMO)
    return CAN_TIMEOUT_ERROR;

  /* Copy received message from mailbox to address given in function parameter msg */
  *msg = *ptrmsg;

  /* Free box where message was kept                                         */
  if (_free_box (CAN_mpool, ptrmsg) == 1)
    return CAN_DEALLOC_MEM_ERROR;

  return CAN_OK;