【三分钟学习FFMPEG一个知识点】FFMPEG关于avio_alloc_context申请使用内存释放问题
生活随笔
收集整理的這篇文章主要介紹了
【三分钟学习FFMPEG一个知识点】FFMPEG关于avio_alloc_context申请使用内存释放问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
問題:
使用ffmpeg發(fā)現(xiàn)av_malloc申請(qǐng)的內(nèi)存最后不能用av_free函數(shù)釋放,會(huì)崩潰。
代碼示例:
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申请使用内存释放问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 互联网日报 | 3月22日 星期一 |
- 下一篇: 解读中国互联网:局部领先、快进的数字化发