X3 SDB多媒体开发内存泄漏问题

用户您好,请详细描述您所遇到的问题:

在提供的示例代码里,很容易的在 sample_osd, sample_vps 里找到如下代码

memset(&feedback_buf, 0, sizeof(hb_vio_buffer_t));
  size_y = max_width * max_height;
  size_uv = size_y / 2;
  prepare_user_buf(&feedback_buf, size_y, size_uv);
  feedback_buf.img_info.planeCount = 2;
  feedback_buf.img_info.img_format = 8;
  feedback_buf.img_addr.width = max_width;
  feedback_buf.img_addr.height = max_height;
  feedback_buf.img_addr.stride_size = max_width;

关于prepare_user_buf 函数我先贴出来,如下

int prepare_user_buf(void *buf, uint32_t size_y, uint32_t size_uv)
{
    int ret;
    hb_vio_buffer_t *buffer = (hb_vio_buffer_t *)buf;
  
    if (buffer == NULL)
        return -1;
  
    buffer->img_info.fd[0] = ion_open();
    buffer->img_info.fd[1] = ion_open();
  
    ret = ion_alloc_phy(size_y, &buffer->img_info.fd[0], &buffer->img_addr.addr[0], &buffer->img_addr.paddr[0]);
    if (ret) {
        printf("prepare user buf error\n");
        return ret;
    }

    ret = ion_alloc_phy(size_uv, &buffer->img_info.fd[1], &buffer->img_addr.addr[1], &buffer->img_addr.paddr[1]);
    if (ret) {
        printf("prepare user buf error\n");
        return ret;
    }
  
    printf("buf:y: vaddr = 0x%s paddr = 0x%lx; uv: vaddr = 0x%s, paddr = 0x%lx\n",
    buffer->img_addr.addr[0], buffer->img_addr.paddr[0],
    buffer->img_addr.addr[1], buffer->img_addr.paddr[1]);
  
    return 0;
}

其中 ion_alloc_phy 函数是在示例代码里声明的,并不是在官方提供的sdk源码中声明的,这一点就很疑惑,很自然的就会问这个函数的实现会在哪里?对应的内存释放函数在哪里?-
然而却能看到下面的官方接口,用来释放 hb_vio_buffer_t 结构体的,但是示例代码里没有说明如何释放通过ion_alloc_phy申请的内存

ret = HB_VPS_ReleaseChnFrame(VpsGrp, vps_chn_index, &chn_2_out_buf);

导致现在的问题是:-
封装OSD功能的类会反复new 和 delete,因为硬件OSD仅仅只支持1路,所以有这个需求。现在不知道如何释放prepare_user_buf 函数中 申请的 buffer->img_addr.addr[0]buffer->img_addr.addr[1] 的内存,导致内存泄漏,

以下尝试均无效:

  • 1.使用 HB_VPS_ReleaseChnFrame 函数来释放 feedback_buf ,无效, 提示如下输出

    [ERROR]["vps"][vps/hb_vps_api.c:2570] [862861.268557]HB_VPS_ReleaseChnFrame[2570]: VPS ReleaseChnFrame error: unexist frame!
    
  • 2.hb_vio_free_ipubuf(feedback_buf.img_info.pipeline_id, &feedback_buf); 无效, 提示如下输出

    [ERROR]["LOG"][hb_vio_interface.c:546] [863089.043902]hb_vio_free_ipubuf[546]: pipe(0) was null !
    
  • 3.尝试使用 free 函数来释放,无效

  • 4.尝试使用 delete 函数来释放,无效

  • 5.尝试使用 delete [] 函数来释放,无效

今天在测试时,当前代码反复new, delete 9次后就会报下面的错误:

[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.37510][3955207:3965179][TREE_NODE] <mem_insert_mem_fd_node:319> Same fd 66 in the node tree.
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.37522][3955207:3965179][MEM_ALLOCATOR] <mem_insert_com_buf_fd_tree:42> Fail to insert memory node(Invalid parameters).
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.37576][3955207:3965179][MEM_ALLOCATOR] <mem_try_alloc_com_buf_locked:137> Fail to update memory node(Invalid file descriptor).
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.37578][3955207:3965179][MEM_ALLOCATOR] <hb_mem_alloc_com_buf_with_lable:259> Fail to allocate common buffer(ret=-16777211).
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.37581][3955207:3965179][HBMEM] <hbmem_alloc:125> Fail to allocate buffer(ret=-16777211).
[ERROR]["multimedia"][src/vdi/linux/vdi_osal.c:174] [ERROR][943236.37583][3955207:3965179][MIANHELPER] hbmem_alloc failed
[ERROR]["multimedia"][src/vdi/linux/vdi_osal.c:174] [ERROR][943236.37588][3955207:3965179]AllocateDecFrameBuffer:1426 fail to allocate frame buffer
[ERROR]["multimedia"][src/vdi/linux/vdi_osal.c:174] [ERROR][943236.38050][3955207:3965179][VDI] invalid buffer to free address = 0x0
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.38198][3955207:3955229][TREE_NODE] <mem_insert_mem_fd_node:319> Same fd 66 in the node tree.
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.38202][3955207:3955229][MEM_ALLOCATOR] <mem_insert_com_buf_fd_tree:42> Fail to insert memory node(Invalid parameters).
[ERROR]["vdec"][video/src/hb_vdec.c:438] [943236.382259]HB_VDEC_QueryStatus[438]: [HB_VDEC] HB_VDEC_QueryStatus:438 Failed to hb_mm_mc_release VeChn = 0 s32Ret = -269024256 

HB_VDEC_QueryStatus  error:-269024256
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.38236][3955207:3955229][MEM_ALLOCATOR] <mem_try_alloc_com_buf_locked:137> Fail to update memory node(Invalid file descriptor).
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.38239][3955207:3955229][MEM_ALLOCATOR] <hb_mem_alloc_com_buf_with_lable:259> Fail to allocate common buffer(ret=-16777211).
[ERROR]["LOG"][src/utils/mem_log.c:108] [ERROR][943236.38242][3955207:3955229][HBMEM] <hbmem_alloc:125> Fail to allocate buffer(ret=-16777211).
mmzFree paddr = 0x1769a000, vaddr = 0x7fa005d000 i = 0, ret=0
[ERROR]["vio_bufmgr"][utils/hb_vio_buffer_mgr.c:364] [943236.382441]ion_alloc_phy_type[364]: hbmem_alloc failed

prepare user buf error ret:-1
error. prepare_user_buf: -1

猜测是前8次的new操作一共调用了8次prepare_user_buf函数,等于调用了16次ion_alloc_phy 函数而没有将这些内存回收,导致ION内存满了,请问如何正确的回收ion_alloc_phy函数申请的双内存

楼主解决了吗?怎么解决的呢,我也遇到了这个问题