Question:
Using ffmpeg to discover AV_ The memory requested by malloc can’t use AV in the end_ If the free function is released, it will crash.
Code example:
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;
}
/*.........*/
Release Avio_ alloc_ Context memory
Method 1: use Avio_ context_ free
avio_context_free(&avio );
Method 2: using AV_ freep
// memory release
av_freep(&avio ->buffer);
av_freep(&avio);
Appendix:
/**
* 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);
Read More:
- Popen error: cannot allocate memory [How to Solve]
- Memory error: cannot allocate memory [How to Solve]
- How to Delete New Memory in Vector
- [Solved] Internal error XFS_WANT_CORRUPTED_GOTO at line 1635 of file fs/xfs/libxfs/xfs_alloc.c.
- Ffmpeg: How to Solve error initializing filter ‘gltransition’
- [Solved] Module yaml error: Unexpected key in data: static_context
- Error Running Context: The server unexpectedly closed the connection
- [Solved] ffmpeg Error: fatal error: zlib.h: Not having that file or directory
- The Linux setroubleshootd process occupies too much memory [How to Solve]
- [Linux] ps+awk +while View process memory usage in real time
- [Solved] NIC cannot be generated vf, intel/mellanox, write error: Cannot allocate memory “not enough MMIO resources for SR-IOV”
- [Solved] fatal error: cannot write PCH file: required memory segment unavailable
- [Solved] YarnClientSchedulerBackend: Yarn application has already exited with state FAILED
- Deepin svn Error: svn: E120171: Error running context: An error occurred during SSL communication
- [Solved] Docker Staratup Error: Failed to start Docker Application Container Engineadsafdsad.
- Read and write BMP image with Pure C language
- [Linux] undefined reference to `itoa’
- Linux: How to Fix undefined reference to `itoa’
- How to Create Threads in Linux