From 7b03cd367dd5416a4728ccea7e47dcd2827cbab7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 10 Jan 2023 18:59:21 +0100 Subject: [PATCH] various: replace if + abort() with MP_HANDLE_OOM() MP_HANDLE_OOM also aborts but calls assert() first, which will result in an useful message if compiled in debug mode. --- audio/aframe.c | 6 ++---- audio/decode/ad_spdif.c | 3 +-- audio/out/ao_lavc.c | 3 +-- demux/demux.c | 3 +-- demux/demux_raw.c | 3 +-- filters/f_lavfi.c | 6 ++---- player/audio.c | 6 ++---- video/filter/refqueue.c | 6 ++---- video/filter/vf_d3d11vpp.c | 3 +-- video/filter/vf_vavpp.c | 3 +-- video/mp_image.c | 12 ++++-------- video/out/dr_helper.c | 3 +-- video/out/gpu/lcms.c | 6 ++---- video/out/gpu/shader_cache.c | 3 +-- video/out/vo.c | 3 +-- video/out/vo_lavc.c | 3 +-- 16 files changed, 24 insertions(+), 48 deletions(-) diff --git a/audio/aframe.c b/audio/aframe.c index 9b0827f64c..cb6ea17be3 100644 --- a/audio/aframe.c +++ b/audio/aframe.c @@ -52,8 +52,7 @@ struct mp_aframe *mp_aframe_create(void) { struct mp_aframe *frame = talloc_zero(NULL, struct mp_aframe); frame->av_frame = av_frame_alloc(); - if (!frame->av_frame) - abort(); + MP_HANDLE_OOM(frame->av_frame); talloc_set_destructor(frame, free_frame); mp_aframe_reset(frame); return frame; @@ -701,8 +700,7 @@ int mp_aframe_pool_allocate(struct mp_aframe_pool *pool, struct mp_aframe *frame if (planes > AV_NUM_DATA_POINTERS) { av_frame->extended_data = av_calloc(planes, sizeof(av_frame->extended_data[0])); - if (!av_frame->extended_data) - abort(); + MP_HANDLE_OOM(av_frame->extended_data); } else { av_frame->extended_data = av_frame->data; } diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c index 3b799660c1..decd97206d 100644 --- a/audio/decode/ad_spdif.c +++ b/audio/decode/ad_spdif.c @@ -169,8 +169,7 @@ static int init_filter(struct mp_filter *da, AVPacket *pkt) goto fail; void *buffer = av_mallocz(OUTBUF_SIZE); - if (!buffer) - abort(); + MP_HANDLE_OOM(buffer); lavf_ctx->pb = avio_alloc_context(buffer, OUTBUF_SIZE, 1, spdif_ctx, NULL, write_packet, NULL); if (!lavf_ctx->pb) { diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index cb53407eb6..abeefeed27 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -210,8 +210,7 @@ static void encode(struct ao *ao, struct mp_aframe *af) double outpts = mp_aframe_get_pts(af); AVFrame *frame = mp_aframe_to_avframe(af); - if (!frame) - abort(); + MP_HANDLE_OOM(frame); frame->pts = rint(outpts * av_q2d(av_inv_q(encoder->time_base))); diff --git a/demux/demux.c b/demux/demux.c index b6e85330ed..15ed27af73 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -2658,8 +2658,7 @@ static int dequeue_packet(struct demux_stream *ds, double min_pts, return -1; ds->attached_picture_added = true; struct demux_packet *pkt = demux_copy_packet(ds->sh->attached_picture); - if (!pkt) - abort(); + MP_HANDLE_OOM(pkt); pkt->stream = ds->sh->index; *res = pkt; return 1; diff --git a/demux/demux_raw.c b/demux/demux_raw.c index edc89e7418..4884b78b37 100644 --- a/demux/demux_raw.c +++ b/demux/demux_raw.c @@ -247,8 +247,7 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check) c->disp_h = height; if (mp_imgfmt) { c->lav_codecpar = avcodec_parameters_alloc(); - if (!c->lav_codecpar) - abort(); + MP_HANDLE_OOM(c->lav_codecpar); c->lav_codecpar->codec_type = AVMEDIA_TYPE_VIDEO; c->lav_codecpar->codec_id = mp_codec_to_av_codec_id(decoder); c->lav_codecpar->format = imgfmt2pixfmt(mp_imgfmt); diff --git a/filters/f_lavfi.c b/filters/f_lavfi.c index 41a3ea4eac..14ed2483a2 100644 --- a/filters/f_lavfi.c +++ b/filters/f_lavfi.c @@ -260,8 +260,7 @@ static void precreate_graph(struct lavfi *c, bool first_init) c->failed = false; c->graph = avfilter_graph_alloc(); - if (!c->graph) - abort(); + MP_HANDLE_OOM(c->graph); if (mp_set_avopts(c->log, c->graph, c->graph_opts) < 0) goto error; @@ -852,8 +851,7 @@ static struct lavfi *lavfi_alloc(struct mp_filter *parent) c->log = f->log; c->public.f = f; c->tmp_frame = av_frame_alloc(); - if (!c->tmp_frame) - abort(); + MP_HANDLE_OOM(c->tmp_frame); return c; } diff --git a/player/audio.c b/player/audio.c index 40a6a3a32a..0e48731e33 100644 --- a/player/audio.c +++ b/player/audio.c @@ -313,8 +313,7 @@ static bool keep_weak_gapless_format(struct mp_aframe *old, struct mp_aframe* ne { bool res = false; struct mp_aframe *new_mod = mp_aframe_new_ref(new); - if (!new_mod) - abort(); + MP_HANDLE_OOM(new_mod); // If the sample formats are compatible (== libswresample generally can // convert them), keep the AO. On other changes, recreate it. @@ -366,8 +365,7 @@ static int reinit_audio_filters_and_output(struct MPContext *mpctx) // The "ideal" filter output format struct mp_aframe *out_fmt = mp_aframe_new_ref(ao_c->filter->output_aformat); - if (!out_fmt) - abort(); + MP_HANDLE_OOM(out_fmt); if (!mp_aframe_config_is_valid(out_fmt)) { talloc_free(out_fmt); diff --git a/video/filter/refqueue.c b/video/filter/refqueue.c index 964fa29c08..e97e85bfaa 100644 --- a/video/filter/refqueue.c +++ b/video/filter/refqueue.c @@ -68,8 +68,7 @@ struct mp_refqueue *mp_refqueue_alloc(struct mp_filter *f) q->filter = f; q->conv = mp_autoconvert_create(f); - if (!q->conv) - abort(); + MP_HANDLE_OOM(q->conv); q->in = q->conv->f->pins[1]; mp_pin_connect(q->conv->f->pins[0], f->ppins[0]); @@ -267,8 +266,7 @@ struct mp_image *mp_refqueue_execute_reinit(struct mp_refqueue *q) mp_refqueue_flush(q); q->in_format = mp_image_new_ref(cur); - if (!q->in_format) - abort(); + MP_HANDLE_OOM(q->in_format); mp_image_unref_data(q->in_format); mp_refqueue_add_input(q, cur); diff --git a/video/filter/vf_d3d11vpp.c b/video/filter/vf_d3d11vpp.c index df029417b9..2f05219976 100644 --- a/video/filter/vf_d3d11vpp.c +++ b/video/filter/vf_d3d11vpp.c @@ -102,8 +102,7 @@ static struct mp_image *alloc_pool(void *pctx, int fmt, int w, int h) return NULL; struct mp_image *mpi = mp_image_new_custom_ref(NULL, texture, release_tex); - if (!mpi) - abort(); + MP_HANDLE_OOM(mpi); mp_image_setfmt(mpi, IMGFMT_D3D11); mp_image_set_size(mpi, w, h); diff --git a/video/filter/vf_vavpp.c b/video/filter/vf_vavpp.c index 8d58fb173b..affb1a1c48 100644 --- a/video/filter/vf_vavpp.c +++ b/video/filter/vf_vavpp.c @@ -172,8 +172,7 @@ static struct mp_image *alloc_out(struct mp_filter *vf) } AVFrame *av_frame = av_frame_alloc(); - if (!av_frame) - abort(); + MP_HANDLE_OOM(av_frame); if (av_hwframe_get_buffer(p->hw_pool, av_frame, 0) < 0) { MP_ERR(vf, "Failed to allocate frame from hw pool.\n"); av_frame_free(&av_frame); diff --git a/video/mp_image.c b/video/mp_image.c index 533061465d..6c28a54c47 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -1102,24 +1102,21 @@ struct AVFrame *mp_image_to_av_frame(struct mp_image *src) dst->chroma_location = mp_chroma_location_to_av(src->params.chroma_location); dst->opaque_ref = av_buffer_alloc(sizeof(struct mp_image_params)); - if (!dst->opaque_ref) - abort(); + MP_HANDLE_OOM(dst->opaque_ref); *(struct mp_image_params *)dst->opaque_ref->data = src->params; if (src->icc_profile) { AVFrameSideData *sd = av_frame_new_side_data_from_buf(dst, AV_FRAME_DATA_ICC_PROFILE, new_ref->icc_profile); - if (!sd) - abort(); + MP_HANDLE_OOM(sd); new_ref->icc_profile = NULL; } if (src->params.color.sig_peak) { AVContentLightMetadata *clm = av_content_light_metadata_create_side_data(dst); - if (!clm) - abort(); + MP_HANDLE_OOM(clm); clm->MaxCLL = src->params.color.sig_peak * MP_REF_WHITE; } @@ -1130,8 +1127,7 @@ struct AVFrame *mp_image_to_av_frame(struct mp_image *src) if (!av_frame_get_side_data(dst, mpsd->type)) { AVFrameSideData *sd = av_frame_new_side_data_from_buf(dst, mpsd->type, mpsd->buf); - if (!sd) - abort(); + MP_HANDLE_OOM(sd); mpsd->buf = NULL; } } diff --git a/video/out/dr_helper.c b/video/out/dr_helper.c index 78d4633efb..5b585f5528 100644 --- a/video/out/dr_helper.c +++ b/video/out/dr_helper.c @@ -140,8 +140,7 @@ static void sync_get_image(void *ptr) AVBufferRef *new_ref = av_buffer_create(ctx->ref->data, ctx->ref->size, free_dr_buffer_on_dr_thread, ctx, 0); - if (!new_ref) - abort(); // tiny malloc OOM + MP_HANDLE_OOM(new_ref); cmd->res->bufs[0] = new_ref; diff --git a/video/out/gpu/lcms.c b/video/out/gpu/lcms.c index b49b9614a2..3df5eba5f2 100644 --- a/video/out/gpu/lcms.c +++ b/video/out/gpu/lcms.c @@ -317,8 +317,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d, if (vid_profile) { MP_VERBOSE(p, "Got an embedded ICC profile.\n"); p->vid_profile = av_buffer_ref(vid_profile); - if (!p->vid_profile) - abort(); + MP_HANDLE_OOM(p->vid_profile); } if (!gl_parse_3dlut_size(p->opts->size_str, &s_r, &s_g, &s_b)) @@ -344,8 +343,7 @@ bool gl_lcms_get_lut3d(struct gl_lcms *p, struct lut3d **result_lut3d, uint8_t hash[32]; struct AVSHA *sha = av_sha_alloc(); - if (!sha) - abort(); + MP_HANDLE_OOM(sha); av_sha_init(sha, 256); av_sha_update(sha, cache_info, strlen(cache_info)); if (vid_profile) diff --git a/video/out/gpu/shader_cache.c b/video/out/gpu/shader_cache.c index 5436881ded..1d5e563cb8 100644 --- a/video/out/gpu/shader_cache.c +++ b/video/out/gpu/shader_cache.c @@ -579,8 +579,7 @@ static bool create_pass(struct gl_shader_cache *sc, struct sc_entry *entry) cache_dir = mp_get_user_path(tmp, sc->global, sc->cache_dir); struct AVSHA *sha = av_sha_alloc(); - if (!sha) - abort(); + MP_HANDLE_OOM(sha); av_sha_init(sha, 256); av_sha_update(sha, entry->total.start, entry->total.len); diff --git a/video/out/vo.c b/video/out/vo.c index a5458b593e..cf806b2244 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -1431,8 +1431,7 @@ struct vo_frame *vo_frame_ref(struct vo_frame *frame) *new = *frame; for (int n = 0; n < frame->num_frames; n++) { new->frames[n] = mp_image_new_ref(frame->frames[n]); - if (!new->frames[n]) - abort(); // OOM on tiny allocs + MP_HANDLE_OOM(new->frames[n]); } new->current = new->num_frames ? new->frames[0] : NULL; return new; diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c index e817b530e0..8e188b5aab 100644 --- a/video/out/vo_lavc.c +++ b/video/out/vo_lavc.c @@ -217,8 +217,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *voframe) pthread_mutex_unlock(&ectx->lock); AVFrame *frame = mp_image_to_av_frame(mpi); - if (!frame) - abort(); + MP_HANDLE_OOM(frame); frame->pts = rint(outpts * av_q2d(av_inv_q(avc->time_base))); frame->pict_type = 0; // keep this at unknown/undefined