| 
| 连续签到天数:1天 |  | 签到总天数:1023天 |  | 签到总奖励:12600金币 | 
 | 
 
悬赏10金币未解决
 
| 我的8670是双模的,连接耳机后,会继续scan BLE设备。 而BLE设备发送的是定向广播,如果一个BLE设备匹配的是另外一个8670,那当前的8670可以scan到该BLE设备,但总是连接失败,于是就会反复scan,反复连接。
 由于scan到的是ble_adv_event_connectable_directed类型的广播,所以8670会调用ConnectionSmGetAuthDevice函数去查找该设备是否在TDL中,这个函数反复调用多次以后,好像就把堆栈空间耗尽了。当再malloc的时候,就会失败,从而导致程序panic。
 个人认为,函数调用过程中malloc的空间,最终都会合理释放掉,不断产生的消息的载荷,最终也都会释放掉,不明白为什么最后就把空间耗尽了?
 
 
 附:最终产生panic的位置:
 
 复制代码static td_data_t *tdl_find_device(
                        uint8                   addr_type,
                        const bdaddr            *addr, 
                        uint16                  *pp, 
                        uint16                  *pi
                        )
{
    td_data_t *td = (td_data_t *) PanicUnlessMalloc(SIZE_TD_DATA_T);
    one_slot *os = PanicUnlessNew(one_slot); /*每次都在这里panic,无可用空间分配了 */
    uint16 used = 0;
    uint16 pos;
    uint16 idx;
    uint16 max_trusted_devices = MAX_TRUSTED_DEVICES;
    
    read_trusted_device_index(&os->tdi);
    for (idx = 0;
         idx < max_trusted_devices && (pos = os->tdi.order[idx]) != TDI_UNUSED;
         idx++)
    {
        if (PsRetrieve(TRUSTED_DEVICE_LIST + pos, td, SIZE_TD_DATA_T))
        {
            os->dev_taddr.type = unpack_td_bdaddr(&os->dev_taddr.addr, td);
            if (
                os->dev_taddr.type == addr_type && 
                BdaddrIsSame(&os->dev_taddr.addr, addr)
                )
            {
                /* found our device */
                goto out;
            }
            /* mark slot as used */
            used |= 1 << pos;
        }
    }
    /* device data not needed anymore */
    free(td);
    td = NULL;
    if (idx < max_trusted_devices)
    {
        /* find first free slot */
        /* we do know that there is a free slot so no need for checking
         * idx < max_trusted_devices */
        for (pos = 0; used & (1 << pos); pos++);
    }
    else
    {
        /* tdl is full, return the last position */
        idx = max_trusted_devices - 1;
        pos = os->tdi.order[idx];
    }
out:
    free(os);
    if (pp)
    {
        *pp = pos;
    }
    if (pi)
    {
        *pi = idx;
    }
    
    return td;
}
 
 | 
 |