日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【三分钟学习FFMPEG一个知识点】FFMPEG关于avio_alloc_context申请使用内存释放问题

發(fā)布時間:2025/3/15 编程问答 10 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【三分钟学习FFMPEG一个知识点】FFMPEG关于avio_alloc_context申请使用内存释放问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

問題:

使用ffmpeg發(fā)現(xiàn)av_malloc申請的內(nèi)存最后不能用av_free函數(shù)釋放,會崩潰。

代碼示例:

unsigned char * iobuffer = NULL; iobuffer = (unsigned char *)av_malloc(40000);if (iobuffer == NULL){printf("iobuffer av_malloc failed.\n");return -1;}AVIOContext *avio = avio_alloc_context(iobuffer, 40000, 0, this, fill_iobuffer, NULL, NULL);if (avio == NULL){printf(" avio_alloc_context failed.\n");return -1;}/*.........*/

釋放avio_alloc_context的內(nèi)存

方法1:使用avio_context_free

avio_context_free(&avio );

方法2:使用av_freep

// 釋放內(nèi)存av_freep(&avio ->buffer);av_freep(&avio);

附錄:

/*** Free the supplied IO context and everything associated with it.** @param s Double pointer to the IO context. This function will write NULL* into s.*/ void avio_context_free(AVIOContext **s);/*** Free a memory block which has been allocated with a function of av_malloc()* or av_realloc() family, and set the pointer pointing to it to `NULL`.** @code{.c}* uint8_t *buf = av_malloc(16);* av_free(buf);* // buf now contains a dangling pointer to freed memory, and accidental* // dereference of buf will result in a use-after-free, which may be a* // security risk.** uint8_t *buf = av_malloc(16);* av_freep(&buf);* // buf is now NULL, and accidental dereference will only result in a* // NULL-pointer dereference.* @endcode** @param ptr Pointer to the pointer to the memory block which should be freed* @note `*ptr = NULL` is safe and leads to no action.* @see av_free()*/ void av_freep(void *ptr);

總結(jié)

以上是生活随笔為你收集整理的【三分钟学习FFMPEG一个知识点】FFMPEG关于avio_alloc_context申请使用内存释放问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。