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...
 
static voidav_malloc_array (size_t nmemb, size_t size)
 
static 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 222 of file mem.c.

Referenced by a64multi_encode_init(), aac_adtstoasc_filter(), aac_decode_frame(), aac_encode_init(), add_av_stream1(), add_codec(), add_fragment(), add_input_streams(), add_pes_stream(), add_segment(), add_to_pktbuf(), add_to_queue(), aiff_write_packet(), alac_encode_init(), allocate_buffers(), allocate_tables(), 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_audio_resample_init(), 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_cpb_properties_alloc(), av_des_alloc(), av_dict_set(), av_dump_format(), av_expr_parse(), av_fft_init(), av_frame_alloc(), 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_opencl_alloc_external_env(), av_opencl_get_device_list(), 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_resample_init(), 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_find_stream_info(), avformat_new_stream(), avformat_open_input(), avi_read_header(), avi_write_header(), avio_alloc_context(), avio_open_dir(), avpriv_ac3_parse_header(), 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_field_queue(), compute_mask(), config_output(), cook_decode_init(), copy_chapters(), cuda_device_init(), D(), daala_header(), dash_init(), decode_dvd_subtitles(), decode_extradata_ps_mp4(), decode_frame(), decode_init(), decode_pic(), DEF_CHOOSE_FORMAT(), dfa_decode_init(), display_end_segment(), doTest(), dss_read_metadata_string(), dv_read_timecode(), dvbsub_parse_display_definition_segment(), dvbsub_parse_page_segment(), dvbsub_parse_region_segment(), dxva2_alloc(), dxva2_device_create(), dxva2_map_frame(), encode_frame(), encode_init(), encode_picture_ls(), enqueue_packet(), epic_add_pixel_to_cache(), 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_AMediaCodec_createCodecByName(), ff_AMediaCodec_createDecoderByType(), ff_AMediaCodec_createEncoderByType(), ff_AMediaFormat_new(), ff_AMediaFormat_newFromObject(), ff_ass_add_rect(), ff_ass_split(), ff_ass_split_dialog2(), ff_audio_data_alloc(), ff_audio_mix_alloc(), ff_audio_resample_init(), ff_avc_write_annexb_extradata(), ff_cavs_init_top_lines(), ff_celt_init(), 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_encode_init(), ff_mpeg_er_init(), ff_nut_add_sp(), ff_parse_mpeg2_descriptor(), ff_pca_init(), ff_psy_preprocess_init(), 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_schro_queue_push_back(), ff_silk_init(), ff_slice_thread_init(), ff_timefilter_new(), ff_vaapi_encode_init(), ff_vc1_decode_init_alloc_tables(), ff_vs_init(), ff_wms_parse_sdp_a_line(), ffat_init_encoder(), ffio_fdopen(), ffm2_read_header(), ffm_read_header(), ffmal_update_format(), ffmmal_add_packet(), ffmmal_set_ref(), ffserver_parse_acl_row(), ffserver_parse_config_feed(), ffserver_parse_config_redirect(), ffserver_parse_config_stream(), fifo_alloc_common(), 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_new_side_data(), g2m_init_buffers(), gen_sub_bitmap(), generate_fake_vps(), generate_joint_tables(), get_buffer(), get_buffer2(), get_device_list(), get_free_frame(), get_http_header_data(), get_private_data(), get_siz(), get_surface(), gif_encode_init(), gxf_write_header(), handle_file(), handler(), hevc_init_context(), hls_slice_data_wpp(), hnm_decode_init(), hnm_read_header(), htmlencode(), iec61883_callback(), init(), init_bundles(), init_complex_filtergraph(), init_context_defaults(), init_fps(), init_input_filter(), init_muxer(), init_output_stream(), init_pts(), lavfi_read_header(), libkvazaar_init(), libschroedinger_encode_frame(), link_filter_inouts(), load_glyph(), main(), make_eval_expr(), make_field_queue(), make_point(), matroska_parse_frame(), matroska_parse_laces(), matroska_parse_rm_audio(), matroska_parse_tracks(), matroska_parse_webvtt(), mediacodec_decode_init(), mediacodec_wrap_hw_buffer(), 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_sidx(), mov_read_stsd(), 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(), mp3_write_packet(), mpeg_mux_init(), mpeg_mux_write_packet(), mpegts_add_service(), mpegts_init(), mpegts_open_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(), new_connection(), 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(), nvenc_setup_extradata(), ogg_buffer_page(), ogg_build_flac_headers(), ogg_build_opus_headers(), ogg_build_speex_headers(), ogg_build_vp8_headers(), ogg_save(), ogg_write_header(), ogg_write_vorbiscomment(), omx_component_init(), omx_init(), opaque_list_push(), open_input_file(), open_output_file(), opt_channel_layout(), opt_filter_complex(), opt_filter_complex_script(), opus_header(), paf_video_init(), parse_dynamic_acl(), parse_fmtp_config(), parse_inputs(), parse_keyframes_index(), parse_primary(), parse_sws_flags(), parse_vtrk(), pic_arrays_init(), pool_alloc_buffer(), pp_get_context(), prepare_sdp_description(), process_output_surface(), psy_3gpp_init(), pthread_cond_init(), pulse_add_detected_device(), put_main_header(), qsv_decode(), qsv_device_create(), qt_rtp_parse_packet(), qtrle_encode_init(), rdt_parse_b64buf(), read_apic(), read_gab2_sub(), read_geobtag(), read_header(), read_packet(), read_priv(), read_tfra(), reallocAlign(), resample_init(), rl2_decode_init(), rtp_new_connection(), rtp_parse_addr_list(), rv34_decoder_alloc(), sap_write_header(), segment_end(), set_encoder_id(), set_extradata(), setup_hwaccel(), 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(), url_alloc_for_protocol(), url_open_dyn_buf_internal(), utvideo_encode_init(), v4l2_get_device_list(), vaapi_decode_init(), vaapi_device_create(), vaapi_encode_alloc(), vaapi_encode_h264_init_slice_params(), vaapi_encode_h265_init_slice_params(), vaapi_encode_issue(), vaapi_vc1_start_frame(), vc1_decode_frame(), vc1_decode_init(), vc2_encode_init(), vda_old_h264_end_frame(), vdpau_alloc(), 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(), vqa_decode_init(), vtenc_send_frame(), wmv2_encode_init(), worker(), wrapped_avframe_encode(), write_packet(), writer_open(), wtvfile_open_sector(), wv_alloc_frame_context(), X264_frame(), and X264_init().

static void* av_malloc_array ( size_t  nmemb,
size_t  size 
)
inlinestatic

Definition at line 209 of file mem.h.

static void* av_mallocz_array ( size_t  nmemb,
size_t  size 
)
inlinestatic
Examples:
qsvdec.c, remuxing.c, and transcoding.c.

Definition at line 229 of file mem.h.

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_frame_ref(), av_resample_init(), avcodec_fill_audio_frame(), channelmap_filter_frame(), check_stream_max_drift(), cng_decode_init(), compute_mask(), config_input(), config_input_ref(), config_output(), copy_separable_masks(), D(), decode_entropy_coded_image(), 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_slice_buffer_init(), ff_slice_thread_init(), ff_snow_alloc_blocks(), ff_snow_common_init_after_header(), ff_stream_encode_params_copy(), ffserver_parse_config_feed(), ffurl_get_protocols(), find_component(), frame_alloc(), g2m_init_buffers(), g722_encode_init(), get_audio_buffer(), get_buffer(), get_device_list(), get_siz(), h264_init_context(), hds_write_header(), http_server(), 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(), ism_write_header(), ivi_init_tiles(), join_config_output(), join_init(), libopus_encode_init(), main(), mkv_write_header(), mov_init(), mov_read_sidx(), mov_read_stsd(), mp_decode_init(), mxf_compute_index_tables(), new_output_stream(), nvenc_setup_surfaces(), open_input_file(), open_output_file(), opus_decode_init(), pic_arrays_init(), psy_3gpp_init(), qsv_create_mids(), 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(), setup_find_stream_info_opts(), smacker_decode_header_tree(), swri_realloc_audio(), tee_write_header(), thread_init_internal(), tiff_decode_tag(), try_push_frame(), 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_file(), append_extradata(), av_bprint_alloc(), av_bprint_finalize(), av_buffer_realloc(), av_dict_set(), av_fast_realloc(), 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_frame(), 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(), frame_new_side_data(), get_qt_codec(), huf_build_dec_table(), load_textfile(), main(), match_streams(), matroska_decode_buffer(), matroska_deliver_packet(), matroska_parse_wavpack(), mov_fix_index(), mov_read_ctts(), mov_read_trun(), nut_read_header(), 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(), append_flv_data(), asfrtp_parse_packet(), auxiliary_info_alloc_size(), av_probe_input_buffer2(), av_vdpau_bind_context(), avi_read_header(), bmv_read_packet(), concat_open(), concatenate_packet(), daala_header(), decode_frame(), decode_registered_user_data_closed_caption(), dxv_decode(), dyn_buf_write(), ff_lzf_uncompress(), ffm_append_recommended_configuration(), 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(), libschroedinger_encode_frame(), 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 450 of file mem.c.

Referenced by add_ctts_entry(), add_index_entry(), caf_write_packet(), decode_frame(), decode_frame_header(), dirac_combine_frame(), ff_add_index_entry(), ff_af_queue_add(), ff_combine_frame(), ff_mms_asf_header_parser(), ff_subtitles_queue_insert(), ff_thread_release_buffer(), ff_vdpau_add_buffer(), ff_videotoolbox_h264_decode_slice(), filter_frame(), flac_fifo_read_wrap(), get_stats(), init(), intercept_id3(), mxg_update_cache(), read_frame(), shorten_decode_frame(), spdif_header_eac3(), vda_old_h264_decode_slice(), and videotoolbox_buffer_copy().

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 469 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(), 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(), lag_decode_frame(), 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 474 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 204 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 213 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 237 of file mem.c.

Referenced by add_av_stream(), add_codec(), 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_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_copy_whiteblacklists(), 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_mpv_encode_init(), ff_stream_encode_params_copy(), ff_tls_open_underlying(), ffio_fdopen(), ffserver_parse_config_feed(), ffserver_parse_config_stream(), ffurl_connect(), fieldmatch_init(), frei0r_init(), ftp_connect(), ftp_current_dir(), ftp_parse_entry_mlsd(), ftp_parse_entry_nlst(), geq_init(), get_cookies(), get_geokey_val(), get_opt_flags_string(), get_ost_filters(), grab_read_header(), hls_delete_old_segments(), hls_start(), hls_write_header(), hls_write_packet(), hls_write_trailer(), http_connect(), http_open(), icecast_open(), init(), init_filter(), init_filters(), initialize(), join_init(), lavfi_read_header(), libsmbc_read_dir(), libssh_read_dir(), log_callback(), main(), microdvd_read_header(), mkdir_p(), 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_output_file(), open_slave(), opengl_write_header(), opt_filter_complex(), opt_map(), opt_sdp_file(), opt_vstats_file(), parse_channel_expressions(), parse_device_name(), parse_filename(), parse_fmtp(), parse_frames(), parse_location(), parse_playlist(), parse_psfile(), parse_read_interval(), parse_read_intervals(), parse_set_cookie(), parse_source_list(), parse_speaker_pos(), parse_times(), parse_video_var(), plot_freqs(), process_command(), process_line(), pulse_add_detected_device(), pulse_server_info_cb(), qsv_decode_init(), qsv_enc_init(), read_header(), read_ttag(), realtext_read_header(), rtmp_http_open(), sami_paragraph_to_ass(), sap_read_header(), sdl2_write_header(), seg_init(), segment_end(), set_enable_expr(), set_expr(), set_options(), set_string(), show_help(), sls_flag_use_localtime_filename(), sls_flags_filename_process(), split_init(), start_children(), stream_open(), v4l2_get_device_list(), 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 249 of file mem.c.

Referenced by avformat_match_stream_specifier(), mpjpeg_get_boundary(), and parse_cookie().

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 269 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 400 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().