From aa362fdcf440fb747c3aeb377ce51d91cc05f38b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 23 Nov 2023 20:46:25 +0100 Subject: [PATCH] various: replace some OOM handling We prefer to fail fast rather than degrade in unpredictable ways. The example in sub/ is particularly egregious because the code just skips the work it's meant to do when an allocation fails. --- audio/out/ao_coreaudio_utils.c | 6 ++---- sub/img_convert.c | 3 ++- video/filter/vf_vdpaupp.c | 3 +-- video/out/x11_common.c | 3 +-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c index 978165d652..f730beca87 100644 --- a/audio/out/ao_coreaudio_utils.c +++ b/audio/out/ao_coreaudio_utils.c @@ -471,10 +471,8 @@ bool ca_change_physical_format_sync(struct ao *ao, AudioStreamID stream, ca_print_asbd(ao, "setting stream physical format:", &change_format); mp_sem_t wakeup; - if (mp_sem_init(&wakeup, 0, 0)) { - MP_WARN(ao, "OOM\n"); - return false; - } + if (mp_sem_init(&wakeup, 0, 0)) + MP_HANDLE_OOM(0); AudioStreamBasicDescription prev_format; err = CA_GET(stream, kAudioStreamPropertyPhysicalFormat, &prev_format); diff --git a/sub/img_convert.c b/sub/img_convert.c index a70bb0a24c..3c18e1713a 100644 --- a/sub/img_convert.c +++ b/sub/img_convert.c @@ -31,7 +31,8 @@ void mp_blur_rgba_sub_bitmap(struct sub_bitmap *d, double gblur) { struct mp_image *tmp1 = mp_image_alloc(IMGFMT_BGRA, d->w, d->h); - if (tmp1) { // on OOM, skip region + MP_HANDLE_OOM(tmp1); + { struct mp_image s = {0}; mp_image_setfmt(&s, IMGFMT_BGRA); mp_image_set_size(&s, d->w, d->h); diff --git a/video/filter/vf_vdpaupp.c b/video/filter/vf_vdpaupp.c index 0519f5a8b8..b8a5d4194f 100644 --- a/video/filter/vf_vdpaupp.c +++ b/video/filter/vf_vdpaupp.c @@ -74,8 +74,7 @@ static void vf_vdpaupp_process(struct mp_filter *f) struct mp_image *mpi = mp_vdpau_mixed_frame_create(mp_refqueue_get_field(p->queue, 0)); - if (!mpi) - return; // OOM + MP_HANDLE_OOM(mpi); struct mp_vdpau_mixer_frame *frame = mp_vdpau_mixed_frame_get(mpi); if (!mp_refqueue_should_deint(p->queue)) { diff --git a/video/out/x11_common.c b/video/out/x11_common.c index b4605bfd0b..7b51791147 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -1372,8 +1372,7 @@ static void vo_x11_sizehint(struct vo *vo, struct mp_rect rc, bool override_pos) override_pos; // for fullscreen and such XSizeHints *hint = XAllocSizeHints(); - if (!hint) - return; // OOM + MP_HANDLE_OOM(hint); hint->flags |= PSize | (force_pos ? PPosition : 0); hint->x = rc.x0;