FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
Heap Management

Functions responsible for allocating, freeing, and copying memory. More...

Functions

voidav_malloc (size_t size) av_malloc_attrib 1(1)
 Allocate a memory block with alignment suitable for all memory accesses (including vectors if available on the CPU). More...
 
voidav_mallocz (size_t size) av_malloc_attrib 1(1)
 Allocate a memory block with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block. More...
 
voidav_malloc_array (size_t nmemb, size_t size)
 
voidav_mallocz_array (size_t nmemb, size_t size)
 
voidav_calloc (size_t nmemb, size_t size) av_malloc_attrib
 Non-inlined equivalent of av_mallocz_array(). More...
 
voidav_realloc (void *ptr, size_t size) 1(2)
 Allocate, reallocate, or free a block of memory. More...
 
av_warn_unused_result int av_reallocp (void *ptr, size_t size)
 Allocate, reallocate, or free a block of memory through a pointer to a pointer. More...
 
voidav_realloc_f (void *ptr, size_t nelem, size_t elsize)
 Allocate, reallocate, or free a block of memory. More...
 
voidav_realloc_array (void *ptr, size_t nmemb, size_t size)
 
int av_reallocp_array (void *ptr, size_t nmemb, size_t size)
 
voidav_fast_realloc (void *ptr, unsigned int *size, size_t min_size)
 Reallocate the given buffer if it is not large enough, otherwise do nothing. More...
 
void av_fast_malloc (void *ptr, unsigned int *size, size_t min_size)
 Allocate a buffer, reusing the given one if large enough. More...
 
void av_fast_mallocz (void *ptr, unsigned int *size, size_t min_size)
 Allocate and clear a buffer, reusing the given one if large enough. More...
 
void av_free (void *ptr)
 Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family. More...
 
void av_freep (void *ptr)
 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. More...
 
char * av_strdup (const char *s) av_malloc_attrib
 Duplicate a string. More...
 
char * av_strndup (const char *s, size_t len) av_malloc_attrib
 Duplicate a substring of a string. More...
 
voidav_memdup (const void *p, size_t size)
 Duplicate a buffer with av_malloc(). More...
 
void av_memcpy_backptr (uint8_t *dst, int back, int cnt)
 Overlapping memcpy() implementation. More...
 

Detailed Description

Functions responsible for allocating, freeing, and copying memory.

All memory allocation functions have a built-in upper limit of INT_MAX bytes. This may be changed with av_max_alloc(), although exercise extreme caution when doing so.

Function Documentation

void* av_malloc ( size_t  size)

Allocate a memory block with alignment suitable for all memory accesses (including vectors if available on the CPU).

Parameters
sizeSize in bytes for the memory block to be allocated
Returns
Pointer to the allocated block, or NULL if the block cannot be allocated
See Also
av_mallocz()

Definition at line 77 of file mem.c.

Referenced by av_malloc(), av_malloc_array(), av_mallocz(), and av_memdup().

void* av_mallocz ( size_t  size)

Allocate a memory block with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block.

Parameters
sizeSize in bytes for the memory block to be allocated
Returns
Pointer to the allocated block, or NULL if it cannot be allocated
See Also
av_malloc()

Definition at line 236 of file mem.c.

Referenced by a64multi_encode_init(), aac_encode_init(), add_fragment(), add_input_streams(), add_pes_stream(), add_segment(), add_to_queue(), aiff_write_packet(), alac_encode_init(), allocate_buffers(), allocate_tables(), amf_encode_init_h264(), amf_encode_init_hevc(), ape_read_header(), apng_write_header(), asf_read_picture(), asf_read_stream_properties(), ass_decode_frame(), atrac3_decode_init(), av_abuffersink_params_alloc(), av_aes_alloc(), av_aes_ctr_alloc(), av_audio_fifo_alloc(), av_bitstream_filter_filter(), av_bitstream_filter_init(), av_blowfish_alloc(), av_bsf_alloc(), av_bsf_list_alloc(), av_buffer_create(), av_buffer_pool_init(), av_buffer_pool_init2(), av_buffer_ref(), av_buffersrc_parameters_alloc(), av_calloc(), av_camellia_alloc(), av_cast5_alloc(), av_content_light_metadata_alloc(), av_cpb_properties_alloc(), av_des_alloc(), av_dict_set(), av_dump_format(), av_encryption_info_alloc(), av_encryption_init_info_alloc(), av_expr_parse(), av_fft_init(), av_frame_alloc(), av_frame_new_side_data_from_buf(), av_hash_alloc(), av_hmac_alloc(), av_hwdevice_ctx_alloc(), av_hwdevice_get_hwframe_constraints(), av_hwdevice_hwconfig_alloc(), av_hwframe_ctx_alloc(), av_mallocz_array(), av_mastering_display_metadata_alloc(), av_md5_alloc(), av_murmur3_alloc(), av_new_program(), av_opt_query_ranges_default(), av_packet_alloc(), av_packet_new_side_data(), av_packet_split_side_data(), av_parser_init(), av_rc4_alloc(), av_ripemd_alloc(), av_sha512_alloc(), av_sha_alloc(), av_spherical_alloc(), av_stereo3d_alloc(), av_tea_alloc(), av_thread_message_queue_alloc(), av_tree_node_alloc(), av_twofish_alloc(), av_vdpau_alloc_context(), av_vorbis_parse_init(), av_xtea_alloc(), avcodec_dct_alloc(), avcodec_open2(), avcodec_parameters_alloc(), avcodec_parameters_copy(), avcodec_parameters_from_context(), avcodec_parameters_to_context(), avdevice_capabilities_create(), avdevice_list_devices(), avfilter_graph_alloc(), avfilter_graph_queue_command(), avfilter_inout_alloc(), avfilter_link(), avformat_alloc_context(), avformat_alloc_output_context2(), avformat_new_stream(), avformat_open_input(), avi_read_header(), avi_write_header(), avio_open_dir(), avpriv_dv_init_demux(), avpriv_float_dsp_alloc(), avpriv_mpegts_parse_open(), avpriv_new_chapter(), avresample_alloc_context(), avui_encode_init(), bfi_decode_init(), callback(), che_configure(), check_add_bytes(), check_add_gradient_pred(), check_add_int16(), check_add_left_pred(), check_add_median_pred(), check_field_queue(), codec_create(), config_output(), cook_decode_init(), copy_chapters(), copy_init_section(), cuda_device_init(), cuvid_decode_init(), D(), daala_header(), dash_init(), decklink_autodetect(), decode_dvd_subtitles(), decode_extradata_ps_mp4(), decode_frame(), decode_init(), decode_pic(), DEF_CHOOSE_FORMAT(), dfa_decode_init(), display_end_segment(), do_encrypt(), doTest(), drm_map_frame(), dss_read_metadata_string(), dv_read_timecode(), dvbsub_parse_display_definition_segment(), dvbsub_parse_page_segment(), dvbsub_parse_region_segment(), dxva2_device_create(), dxva2_map_frame(), encode_frame(), encode_init(), encode_picture_ls(), enqueue_packet(), epic_add_pixel_to_cache(), extract_extradata(), ff_all_channel_counts(), ff_all_channel_layouts(), ff_all_samplerates(), ff_alloc_a53_sei(), ff_alloc_dir_entry(), ff_alloc_input_device_context(), ff_alsa_get_device_list(), ff_AMediaFormat_new(), ff_AMediaFormat_newFromObject(), ff_ass_add_rect(), ff_ass_split(), ff_ass_split_dialog2(), ff_attach_decode_data(), ff_audio_data_alloc(), ff_audio_mix_alloc(), ff_audio_resample_init(), ff_avc_write_annexb_extradata(), ff_cavs_init_top_lines(), ff_cbs_alloc_unit_content(), ff_cbs_h264_add_sei_message(), ff_cbs_init(), ff_celt_init(), ff_decklink_list_devices(), ff_decklink_list_devices_legacy(), ff_decklink_read_header(), ff_decklink_write_header(), ff_dither_alloc(), ff_ebur128_init(), ff_fast_malloc(), ff_fbdev_get_device_list(), ff_ffv1_init_slice_contexts(), ff_filter_alloc(), ff_frame_pool_audio_init(), ff_frame_pool_video_init(), ff_frame_thread_encoder_init(), ff_frame_thread_init(), ff_graph_thread_init(), ff_hevc_decode_nal_pps(), ff_hwframe_map_create(), ff_iir_filter_init_state(), ff_init_vscale(), ff_interleave_add_packet(), ff_intrax8_common_init(), ff_ivi_init_planes(), ff_jpegls_decode_picture(), ff_lpc_init(), ff_lzw_decode_open(), ff_mdct15_init(), ff_merge_channel_layouts(), ff_mjpeg_decode_sof(), ff_mjpeg_encode_init(), ff_mpeg_er_init(), ff_nut_add_sp(), ff_nvdec_decode_init(), ff_nvdec_start_frame(), ff_opus_psy_init(), ff_packet_list_put(), ff_parse_mpeg2_descriptor(), ff_pca_init(), ff_psy_preprocess_init(), ff_qsvvpp_create(), ff_rate_control_init(), ff_rdt_parse_open(), ff_read_riff_info(), ff_rfps_add_frame(), ff_rm_alloc_rmstream(), ff_rtp_parse_open(), ff_rtsp_setup_output_streams(), ff_silk_init(), ff_slice_thread_init(), ff_timefilter_new(), ff_v4l2_context_init(), ff_v4l2_m2m_create_context(), ff_vaapi_encode_init(), ff_vc1_decode_init_alloc_tables(), ff_videotoolbox_alloc_frame(), ff_vs_init(), ff_wms_parse_sdp_a_line(), ffat_decode(), ffat_init_decoder(), ffat_init_encoder(), ffio_fdopen(), ffmal_update_format(), ffmmal_add_packet(), ffmmal_set_ref(), fifo_alloc_common(), film_write_packet(), filter_frame(), find_component(), find_headers_search_validate(), flac_read_header(), flashsv2_encode_init(), flashsv_decode_frame(), flashsv_encode_frame(), flashsv_encode_init(), flush_packet(), flv_queue_extradata(), flv_write_header(), flv_write_packet(), frame_alloc(), g2m_init_buffers(), gen_sub_bitmap(), generate_fake_vps(), generate_joint_tables(), get_content_url(), get_current_encryption_info(), get_current_fragment(), get_Fragment(), get_free_frame(), get_http_header_data(), get_private_data(), get_siz(), get_surface(), gif_encode_init(), gxf_write_header(), h264_metadata_filter(), handle_file(), handler(), hevc_init_context(), hls_slice_data_wpp(), hls_start(), hnm_decode_init(), hnm_read_header(), hw_device_add(), hwaccel_init(), iec61883_callback(), init(), init_bundles(), init_complex_filtergraph(), init_context_defaults(), init_fps(), init_input_filter(), init_muxer(), init_output_stream(), init_pts(), kmsgrab_read_packet(), lavfi_read_header(), libcodec2_init_encoder(), libkvazaar_init(), link_filter_inouts(), load_glyph(), magy_encode_init(), main(), make_eval_expr(), make_field_queue(), make_point(), matroska_parse_laces(), matroska_parse_tracks(), mediacodec_decode_init(), mediacodec_wrap_hw_buffer(), mjpeg_decode_app(), mkv_start_cues(), mkv_start_seekhead(), mkv_write_attachments(), mkv_write_header(), mmsh_open_internal(), mmsh_read_seek(), mov_read_chapters(), mov_read_covr(), mov_read_dref(), mov_read_keys(), mov_read_pssh(), mov_read_stsd(), mov_read_tenc(), mov_read_trak(), mov_read_udta_string(), mov_read_uuid(), mov_read_wave(), mov_rewrite_dvd_sub_extradata(), mov_text_encode_init(), mov_text_tx3g(), mov_write_dvc1_structs(), mov_write_single_packet(), mpeg_decode_a53_cc(), mpeg_mux_init(), mpeg_mux_write_packet(), mpegts_add_service(), mpegts_init(), mpegts_open_filter(), mpegts_open_section_filter(), mss2_decode_init(), mxf_handle_missing_index_segment(), mxf_parse_package_comments(), mxf_read_local_tags(), mxf_uid_to_str(), mxf_umid_to_str(), mxf_write_header(), mxpeg_decode_mxm(), ndi_setup_audio(), ndi_setup_video(), new_init_section(), new_output_stream(), new_playlist(), new_rendition(), new_stream(), new_variant(), new_video_stream(), nsv_parse_NSVf_header(), nsv_parse_NSVs_header(), nvdec_decoder_create(), nvenc_setup_extradata(), ogg_buffer_page(), ogg_build_flac_headers(), ogg_build_opus_headers(), ogg_build_speex_headers(), ogg_build_vp8_headers(), ogg_init(), ogg_save(), ogg_write_vorbiscomment(), omx_component_init(), omx_init(), opaque_list_push(), open_input(), open_input_file(), open_output_file(), opencl_map_frame(), opencl_pool_alloc(), opt_channel_layout(), opt_filter_complex(), opt_filter_complex_script(), opus_header(), overlay_qsv_init(), paf_video_init(), parse_cc_stream_mapstring(), parse_fmtp_config(), parse_inputs(), parse_keyframes_index(), parse_manifest(), parse_manifest_representation(), parse_manifest_segmenttimeline(), parse_primary(), parse_sws_flags(), parse_variant_stream_mapstring(), parse_vtrk(), pic_arrays_init(), pool_alloc_buffer(), pp_get_context(), process_output_surface(), psy_3gpp_init(), pulse_add_detected_device(), put_audio_specific_config(), put_main_header(), qsv_decode(), qsv_device_create(), qt_rtp_parse_packet(), qtrle_encode_init(), rdt_parse_b64buf(), read_apic(), read_chapter(), read_gab2_sub(), read_geobtag(), read_header(), read_header_vs(), read_packet(), read_packet_vs(), read_priv(), reallocAlign(), resample_init(), resolve_content_path(), rkmpp_init_decoder(), rkmpp_retrieve_frame(), rl2_decode_init(), rv34_decoder_alloc(), sap_write_header(), segment_end(), set_encoder_id(), set_extradata(), smacker_decode_header_tree(), smka_decode_frame(), sp5x_decode_frame(), speex_header(), stream_open(), svc_encode_init(), svq1_encode_init(), svq1_encode_plane(), svq3_decode_init(), swr_alloc(), swri_rematrix_init(), sws_alloc_context(), tgv_decode_frame(), theora_header(), update_block_buffers(), update_dimensions(), update_variant_stream_info(), url_alloc_for_protocol(), url_open_dyn_buf_internal(), utvideo_encode_init(), v4l2_get_device_list(), vaapi_device_create(), vaapi_device_derive(), vaapi_encode_alloc(), vaapi_encode_issue(), vc1_decode_frame(), vc1_decode_init(), vc2_encode_init(), videostream_cb(), videotoolbox_init(), vorbis_header(), vorbis_parse_setup_hdr_codebooks(), vorbis_parse_setup_hdr_floors(), vorbis_parse_setup_hdr_mappings(), vorbis_parse_setup_hdr_modes(), vorbis_parse_setup_hdr_residues(), vp6_decode_init(), vp9_raw_reorder_filter(), vqa_decode_init(), vtenc_send_frame(), wmv2_encode_init(), wrap_texture_buf(), wrapped_avframe_encode(), write_packet(), writer_open(), wtvfile_open_sector(), wv_alloc_frame_context(), X264_frame(), and X264_init().

void* av_malloc_array ( size_t  nmemb,
size_t  size 
)

Definition at line 184 of file mem.c.

void* av_mallocz_array ( size_t  nmemb,
size_t  size 
)

Definition at line 191 of file mem.c.

Referenced by a64multi_encode_init(), alloc_buffers(), alloc_sequence_buffers(), alloc_slice(), allocate_buffers(), allocate_tables(), atrac3_decode_init(), atrac3p_decode_init(), audio_get_buffer(), av_audio_fifo_alloc(), av_encryption_info_alloc(), av_encryption_init_info_alloc(), av_frame_ref(), avcodec_fill_audio_frame(), channelmap_filter_frame(), check_add_bytes(), check_add_left_pred(), check_add_left_pred_16(), check_add_median_pred(), check_stream_max_drift(), checkasm_check_nlmeans(), cng_decode_init(), config_input(), config_input_ref(), config_output(), D(), decode_entropy_coded_image(), decode_frame_header(), decode_init(), decode_picture_header(), dejudder_init(), display_end_segment(), dnxhd_decode_init(), dnxhd_decode_init_thread_copy(), dxva2_init_pool(), encode_init(), ff_alloc_entries(), ff_cavs_init_top_lines(), ff_ebur128_init(), ff_ffv1_init_slice_state(), ff_filter_alloc(), ff_frame_pool_get(), ff_frame_thread_init(), ff_init_filters(), ff_init_vscale(), ff_ivi_init_planes(), ff_ivi_init_tiles(), ff_jpeg2000_init_component(), ff_jpeg2000_tag_tree_init(), ff_mjpeg_decode_sof(), ff_mlz_init_dict(), ff_opus_parse_extradata(), ff_png_zalloc(), ff_psy_init(), ff_psy_preprocess_init(), ff_qsv_enc_init(), ff_qsvvpp_create(), ff_slice_buffer_init(), ff_snow_alloc_blocks(), ff_snow_common_init_after_header(), ff_stream_encode_params_copy(), ffurl_get_protocols(), find_component(), g2m_init_buffers(), g722_encode_init(), get_audio_buffer(), get_buffer(), get_siz(), h264_init_context(), hds_write_header(), huf_uncompress(), hwframe_pool_prealloc(), ico_write_header(), init(), init_band(), init_out_session(), init_parse_context(), init_pattern_from_string(), init_prec(), init_tiles(), init_vpp_session(), ism_write_header(), ivi_init_tiles(), join_config_output(), join_init(), jpeg2000_decode_packet(), libopus_encode_init(), main(), mkv_write_header(), mov_init(), mov_read_sample_encryption_info(), mov_read_stsd(), mp_decode_init(), mxf_compute_index_tables(), nvenc_setup_surfaces(), open_input_file(), open_output_file(), opus_decode_init(), overlay_qsv_init(), pic_arrays_init(), program_opencl_init(), psy_3gpp_init(), qsv_create_mids(), qsv_frames_derive_from(), qsv_frames_derive_to(), qsv_frames_init(), qsv_init_pool(), qsv_setup_mids(), qtrle_encode_init(), read_huffman_code_normal(), read_shape_from_file(), read_tfra(), ready_codebook(), ready_residue(), roq_encode_init(), rtsp_read_header(), sap_write_header(), set_gauss(), setup_derivative_buffers(), setup_find_stream_info_opts(), smacker_decode_header_tree(), swri_realloc_audio(), tee_write_header(), tiff_decode_tag(), try_push_frame(), vaapi_encode_issue(), var_size_bme(), vorbis_parse_id_hdr(), vorbis_parse_setup_hdr_codebooks(), vorbis_parse_setup_hdr_floors(), vorbis_parse_setup_hdr_mappings(), XAVS_init(), and xmv_read_header().

void* av_calloc ( size_t  nmemb,
size_t  size 
)
void* av_realloc ( void ptr,
size_t  size 
)

Allocate, reallocate, or free a block of memory.

If ptr is NULL and size > 0, allocate a new block. If size is zero, free the memory block pointed to by ptr. Otherwise, expand or shrink that block of memory according to size.

Parameters
ptrPointer to a memory block already allocated with av_realloc() or NULL
sizeSize in bytes of the memory block to be allocated or reallocated
Returns
Pointer to a newly-reallocated block or NULL if the block cannot be reallocated or the function is used to free the memory block
Warning
Unlike av_malloc(), the returned pointer is not guaranteed to be correctly aligned.
See Also
av_fast_realloc()
av_reallocp()

Definition at line 135 of file mem.c.

Referenced by add_adaptation_set(), add_file(), append_extradata(), av_bprint_alloc(), av_bprint_finalize(), av_buffer_realloc(), av_dict_set(), av_fast_realloc(), av_frame_new_side_data_from_buf(), av_packet_add_side_data(), av_packet_pack_dictionary(), av_realloc_array(), av_realloc_f(), av_reallocp(), av_strdup(), av_stream_add_side_data(), av_strndup(), avfilter_graph_alloc_filter(), concat_open(), decode_header(), draw_text(), epic_hash_add(), ff_els_decode_unsigned(), ff_h264_parse_sprop_parameter_sets(), ff_img_read_header(), ff_rtmp_packet_create(), ff_vs_init(), fixup_vorbis_headers(), huf_build_dec_table(), jpeg2000_decode_packet(), load_textfile(), main(), match_streams(), matroska_decode_buffer(), matroska_parse_wavpack(), mov_fix_index(), ogg_new_stream(), parse_adaptation_sets(), probe_codec(), qt_rtp_parse_packet(), and xmlescape().

av_warn_unused_result int av_reallocp ( void ptr,
size_t  size 
)

Allocate, reallocate, or free a block of memory through a pointer to a pointer.

If *ptr is NULL and size > 0, allocate a new block. If size is zero, free the memory block pointed to by *ptr. Otherwise, expand or shrink that block of memory according to size.

Parameters
[in,out]ptrPointer to a pointer to a memory block already allocated with av_realloc(), or a pointer to NULL. The pointer is updated on success, or freed on failure.
[in]sizeSize in bytes for the memory block to be allocated or reallocated
Returns
Zero on success, an AVERROR error code on failure
Warning
Unlike av_malloc(), the allocated memory is not guaranteed to be correctly aligned.

Definition at line 163 of file mem.c.

Referenced by add_fragment(), add_segment(), add_tracked_method(), aom_init(), append_flv_data(), asfrtp_parse_packet(), auxiliary_info_alloc_size(), av_probe_input_buffer2(), av_vdpau_bind_context(), avi_read_header(), bmv_read_packet(), cbs_av1_write_unit(), cbs_h2645_assemble_fragment(), cbs_h2645_write_nal_unit(), cbs_jpeg_write_unit(), cbs_mpeg2_write_unit(), cbs_vp9_write_unit(), concat_open(), concatenate_packet(), daala_header(), decode_frame(), decode_registered_user_data_closed_caption(), dxv_decode(), dyn_buf_write(), ff_els_decode_unsigned(), ff_lzf_uncompress(), ff_opencl_filter_load_program_from_file(), fixup_vorbis_headers(), flashsv_decode_frame(), g2m_load_cursor(), get_tcp_server_response(), h264_extradata_to_annexb(), handle_metadata(), hap_decode(), hevc_extradata_to_annexb(), http_open(), jpg_decode_data(), mov_cenc_end_packet(), mov_realloc_extradata(), omx_encode_frame(), omx_encode_init(), parse_icy(), qt_rtp_parse_packet(), queue_frames(), rdt_parse_sdp_line(), realloc_buffer(), rtmp_http_write(), rtmp_open(), rtmp_write(), set_segment_filename(), smacker_read_packet(), tdsc_decode_frame(), tdsc_decode_tiles(), tdsc_init(), tdsc_load_cursor(), tgv_decode_inter(), theora_header(), tls_client_handshake_loop(), tls_read(), and vpx_init().

void* av_realloc_f ( void ptr,
size_t  nelem,
size_t  elsize 
)

Allocate, reallocate, or free a block of memory.

This function does the same thing as av_realloc(), except:

  • It takes two size arguments and allocates nelem * elsize bytes, after checking the result of the multiplication for integer overflow.
  • It frees the input block in case of failure, thus avoiding the memory leak with the classic
    buf = realloc(buf);
    if (!buf)
    return -1;
    pattern.

Definition at line 148 of file mem.c.

Referenced by av_reallocp_array().

void* av_realloc_array ( void ptr,
size_t  nmemb,
size_t  size 
)
int av_reallocp_array ( void ptr,
size_t  nmemb,
size_t  size 
)
void* av_fast_realloc ( void ptr,
unsigned int size,
size_t  min_size 
)

Reallocate the given buffer if it is not large enough, otherwise do nothing.

If the given buffer is NULL, then a new uninitialized buffer is allocated.

If the given buffer is not large enough, and reallocation fails, NULL is returned and *size is set to 0, but the original buffer is not changed or freed.

A typical use pattern follows:

uint8_t *buf = ...;
uint8_t *new_buf = av_fast_realloc(buf, &current_size, size_needed);
if (!new_buf) {
// Allocation failed; clean up original buffer
av_freep(&buf);
return AVERROR(ENOMEM);
}
Parameters
[in,out]ptrAlready allocated buffer, or NULL
[in,out]sizePointer to current size of buffer ptr. *size is changed to min_size in case of success or 0 in case of failure
[in]min_sizeNew size of buffer ptr
Returns
ptr if the buffer is large enough, a pointer to newly reallocated buffer if the buffer was not large enough, or NULL in case of error
See Also
av_realloc()
av_fast_malloc()

Definition at line 464 of file mem.c.

Referenced by add_ctts_entry(), add_index_entry(), caf_write_packet(), decode_frame(), dirac_combine_frame(), ff_add_index_entry(), ff_af_queue_add(), ff_combine_frame(), ff_mms_asf_header_parser(), ff_nvdec_simple_decode_slice(), ff_subtitles_queue_insert(), ff_thread_release_buffer(), ff_vdpau_add_buffer(), filter_frame(), flac_fifo_read_wrap(), get_stats(), init(), intercept_id3(), mov_build_index(), mov_parse_auxiliary_info(), mov_read_ctts(), mov_read_pssh(), mov_read_saio(), mov_read_senc(), mov_read_stts(), mov_read_trun(), mov_try_read_block(), mxg_update_cache(), nvdec_h264_decode_slice(), nvdec_hevc_decode_slice(), read_frame(), shorten_decode_frame(), spdif_header_eac3(), update_frag_index(), videotoolbox_buffer_copy(), and videotoolbox_common_decode_slice().

void av_fast_malloc ( void ptr,
unsigned int size,
size_t  min_size 
)

Allocate a buffer, reusing the given one if large enough.

Contrary to av_fast_realloc(), the current buffer contents might not be preserved and on error the old buffer is freed, thus no special handling to avoid memleaks is necessary.

*ptr is allowed to be NULL, in which case allocation always happens if size_needed is greater than 0.

uint8_t *buf = ...;
av_fast_malloc(&buf, &current_size, size_needed);
if (!buf) {
// Allocation failed; buf already freed
return AVERROR(ENOMEM);
}
Parameters
[in,out]ptrPointer to pointer to an already allocated buffer. *ptr will be overwritten with pointer to new buffer on success or NULL on failure
[in,out]sizePointer to current size of buffer *ptr. *size is changed to min_size in case of success or 0 in case of failure
[in]min_sizeNew size of buffer *ptr
See Also
av_realloc()
av_fast_mallocz()

Definition at line 488 of file mem.c.

Referenced by alloc_scratch_buffers(), allocate_buffers(), ape_decode_frame(), audio_decode_frame(), chs_alloc_lsb_band_data(), chs_alloc_msb_band_data(), chs_assemble_freq_bands(), codec_reinit(), crypto_write(), decode_8(), decode_frame(), detect_clips(), do_interpolation(), ff_dca_core_filter_fixed(), ff_mpeg_update_thread_context(), fic_decode_frame(), filter_frame_float(), find_motion(), gif_decode_frame(), gif_read_image(), id3v2_parse(), interpolation(), ljpeg_decode_rgb_scan(), magy_decode_frame(), opus_decode_subpacket(), parse_navi_table(), pmp_packet(), reconfigure_at_keyframe(), rscc_decode_frame(), spdif_header_dts4(), spdif_write_packet(), svq3_decode_slice_header(), tak_decode_frame(), truemotion1_decode_header(), truemotion1_decode_init(), update_init_section(), update_md5_sum(), and verify_md5().

void av_fast_mallocz ( void ptr,
unsigned int size,
size_t  min_size 
)

Allocate and clear a buffer, reusing the given one if large enough.

Like av_fast_malloc(), but all newly allocated space is initially cleared. Reused buffer is not cleared.

*ptr is allowed to be NULL, in which case allocation always happens if size_needed is greater than 0.

Parameters
[in,out]ptrPointer to pointer to an already allocated buffer. *ptr will be overwritten with pointer to new buffer on success or NULL on failure
[in,out]sizePointer to current size of buffer *ptr. *size is changed to min_size in case of success or 0 in case of failure
[in]min_sizeNew size of buffer *ptr
See Also
av_fast_malloc()

Definition at line 493 of file mem.c.

Referenced by alloc_sample_buffer(), alloc_scratch_buffers(), and alloc_x96_sample_buffer().

void av_free ( void ptr)

Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family.

Parameters
ptrPointer to the memory block which should be freed.
Note
ptr = NULL is explicitly allowed.
It is recommended that you use av_freep() instead, to prevent leaving behind dangling pointers.
See Also
av_freep()

Definition at line 218 of file mem.c.

Referenced by av_freep(), and av_realloc_f().

void av_freep ( void ptr)

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.

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.
Parameters
ptrPointer to the pointer to the memory block which should be freed
Note
*ptr = NULL is safe and leads to no action.
See Also
av_free()

Definition at line 227 of file mem.c.

Referenced by av_dynarray2_add(), av_dynarray_add(), and av_reallocp().

char* av_strdup ( const char *  s)

Duplicate a string.

Parameters
sString to be duplicated
Returns
Pointer to a newly-allocated string containing a copy of s or NULL if the string cannot be allocated
See Also
av_strndup()

Definition at line 251 of file mem.c.

Referenced by add_input_streams(), add_tracked_method(), ass_decode_frame(), av_append_path_component(), av_bsf_list_parse_str(), av_dict_get_string(), av_dict_set(), av_opt_copy(), av_opt_get(), avfilter_graph_parse(), avfilter_graph_queue_command(), avfilter_init_str(), avformat_alloc_output_context2(), avformat_match_stream_specifier(), avformat_open_input(), avpriv_tempfile(), bsf_parse_single(), caca_write_header(), choose_pix_fmts(), cine_read_header(), config_input(), config_output(), configure_filtergraph(), convert_sub_to_old_ass_form(), curves_init(), decimate_init(), draw_curves(), ebml_parse_nest(), ff_alsa_get_device_list(), ff_boxblur_eval_filter_params(), ff_copy_whiteblacklists(), ff_decklink_list_devices(), ff_fbdev_get_device_list(), ff_filter_alloc(), ff_http_do_new_request(), ff_http_match_no_proxy(), ff_img_read_header(), ff_jni_jstring_to_utf_chars(), ff_mkdir_p(), ff_stream_encode_params_copy(), ff_tls_open_underlying(), ffio_fdopen(), ffurl_connect(), fieldmatch_init(), format_name(), frei0r_init(), ftp_connect(), ftp_current_dir(), ftp_parse_entry_mlsd(), ftp_parse_entry_nlst(), geq_init(), get_cookies(), get_current_fragment(), get_geokey_val(), get_opt_flags_string(), get_ost_filters(), grab_read_header(), hls_delete_old_segments(), hls_init(), hls_mux_init(), hls_rename_temp_file(), hls_start(), hls_write_packet(), hls_write_trailer(), http_connect(), http_open(), icecast_open(), init(), init_filter(), init_filters(), init_muxer(), initialize(), join_init(), lavfi_read_header(), libsmbc_read_dir(), libsrt_open(), libssh_read_dir(), log_callback(), main(), microdvd_read_header(), mkv_write_simpletag(), mmsh_open_internal(), movie_common_init(), mpegts_add_service(), mpjpeg_read_packet(), mtv_read_header(), new_audio_stream(), new_init_section(), new_output_stream(), new_video_stream(), open_camera(), open_output_file(), open_slave(), opengl_write_header(), opt_filter_complex(), opt_map(), opt_map_channel(), opt_sdp_file(), opt_vstats_file(), parse_cc_stream_mapstring(), parse_channel_expressions(), parse_device_name(), parse_filename(), parse_fmtp(), parse_frames(), parse_location(), parse_manifest(), parse_map(), parse_options(), parse_playlist(), parse_psfile(), parse_read_interval(), parse_read_intervals(), parse_set_cookie(), parse_speaker_pos(), parse_times(), parse_variant_stream_mapstring(), parse_video_var(), plot_freqs(), process_command(), process_line(), pulse_add_detected_device(), pulse_server_info_cb(), qsv_decode_init(), qsv_enc_init(), read_channels(), read_custom_noise(), read_gains(), read_header(), read_tf_coefficients(), read_ttag(), read_zp_coefficients(), realtext_read_header(), rfc4175_parse_fmtp(), rtmp_http_open(), sami_paragraph_to_ass(), sap_read_header(), sap_write_header(), sdl2_write_header(), seg_init(), segment_end(), set_enable_expr(), set_expr(), set_options(), set_segment_filename(), set_string(), show_help(), sls_flags_filename_process(), split_init(), stream_open(), update_master_pl_info(), update_variant_stream_info(), v4l2_get_device_list(), validate_name(), webm_chunk_write_header(), write_option(), X264_init(), xcbgrab_read_header(), and xv_write_header().

char* av_strndup ( const char *  s,
size_t  len 
)

Duplicate a substring of a string.

Parameters
sString to be duplicated
lenMaximum length of the resulting string (not counting the terminating byte)
Returns
Pointer to a newly-allocated string containing a substring of s or NULL if the string cannot be allocated

Definition at line 263 of file mem.c.

Referenced by avformat_match_stream_specifier(), hw_device_init_from_string(), libsrt_open(), mpjpeg_get_boundary(), parse_cookie(), and process_line().

void* av_memdup ( const void p,
size_t  size 
)

Duplicate a buffer with av_malloc().

Parameters
pBuffer to be duplicated
sizeSize in bytes of the buffer copied
Returns
Pointer to a newly allocated buffer containing a copy of p or NULL if the buffer cannot be allocated

Definition at line 283 of file mem.c.

Referenced by av_opt_copy(), clone_filter_formats(), ff_mpv_common_frame_size_change(), ff_mpv_common_init(), ff_stream_encode_params_copy(), and set_aes_arg().

void av_memcpy_backptr ( uint8_t dst,
int  back,
int  cnt 
)

Overlapping memcpy() implementation.

Parameters
dstDestination buffer
backNumber of bytes back to start copying (i.e. the initial size of the overlapping window); must be > 0
cntNumber of bytes to copy; must be >= 0
Note
cnt > back is valid, this will copy the bytes we just copied, thus creating a repeating pattern with a period length of back.

Definition at line 414 of file mem.c.

Referenced by copy_backptr(), decode_dsw1(), decode_frame(), decode_tsw1(), ff_lzf_uncompress(), mszh_decomp(), residual_interp(), synth_block_fcb_acb(), unpack(), and xan_unpack().