mirror of https://github.com/mpv-player/mpv
mp_image: abort on av_buffer_ref() failure
this changes mp_image_new_ref() to handle allocation failure itself instead of doing it at its many call-sites (some of which never checked for failure at all). also remove MP_HANDLE_OOM() from the call sites since this is not necessary anymore. not all the call-sites have been touched, since some of the caller might be relying on `mp_image_new_ref(NULL)` returning NULL. Fixes: https://github.com/mpv-player/mpv/issues/11840
This commit is contained in:
parent
2f220c6286
commit
d70b859084
|
@ -548,7 +548,6 @@ struct sub_bitmaps *sub_bitmaps_copy(struct sub_bitmap_copy_cache **p_cache,
|
|||
assert(in->packed && in->packed->bufs[0]);
|
||||
|
||||
res->packed = mp_image_new_ref(res->packed);
|
||||
MP_HANDLE_OOM(res->packed);
|
||||
talloc_steal(res, res->packed);
|
||||
|
||||
res->parts = NULL;
|
||||
|
|
|
@ -266,7 +266,6 @@ struct mp_image *mp_refqueue_execute_reinit(struct mp_refqueue *q)
|
|||
mp_refqueue_flush(q);
|
||||
|
||||
q->in_format = mp_image_new_ref(cur);
|
||||
MP_HANDLE_OOM(q->in_format);
|
||||
mp_image_unref_data(q->in_format);
|
||||
|
||||
mp_refqueue_add_input(q, cur);
|
||||
|
|
|
@ -314,12 +314,11 @@ void mp_image_unref_data(struct mp_image *img)
|
|||
}
|
||||
}
|
||||
|
||||
static void ref_buffer(bool *ok, AVBufferRef **dst)
|
||||
static void ref_buffer(AVBufferRef **dst)
|
||||
{
|
||||
if (*dst) {
|
||||
*dst = av_buffer_ref(*dst);
|
||||
if (!*dst)
|
||||
*ok = false;
|
||||
MP_HANDLE_OOM(*dst);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,29 +336,22 @@ struct mp_image *mp_image_new_ref(struct mp_image *img)
|
|||
talloc_set_destructor(new, mp_image_destructor);
|
||||
*new = *img;
|
||||
|
||||
bool ok = true;
|
||||
for (int p = 0; p < MP_MAX_PLANES; p++)
|
||||
ref_buffer(&ok, &new->bufs[p]);
|
||||
ref_buffer(&new->bufs[p]);
|
||||
|
||||
ref_buffer(&ok, &new->hwctx);
|
||||
ref_buffer(&ok, &new->icc_profile);
|
||||
ref_buffer(&ok, &new->a53_cc);
|
||||
ref_buffer(&ok, &new->dovi);
|
||||
ref_buffer(&ok, &new->film_grain);
|
||||
ref_buffer(&ok, &new->dovi_buf);
|
||||
ref_buffer(&new->hwctx);
|
||||
ref_buffer(&new->icc_profile);
|
||||
ref_buffer(&new->a53_cc);
|
||||
ref_buffer(&new->dovi);
|
||||
ref_buffer(&new->film_grain);
|
||||
ref_buffer(&new->dovi_buf);
|
||||
|
||||
new->ff_side_data = talloc_memdup(NULL, new->ff_side_data,
|
||||
new->num_ff_side_data * sizeof(new->ff_side_data[0]));
|
||||
for (int n = 0; n < new->num_ff_side_data; n++)
|
||||
ref_buffer(&ok, &new->ff_side_data[n].buf);
|
||||
ref_buffer(&new->ff_side_data[n].buf);
|
||||
|
||||
if (ok)
|
||||
return new;
|
||||
|
||||
// Do this after _all_ bufs were changed; we don't want it to free bufs
|
||||
// from the original image if this fails.
|
||||
talloc_free(new);
|
||||
return NULL;
|
||||
return new;
|
||||
}
|
||||
|
||||
struct free_args {
|
||||
|
|
|
@ -1438,10 +1438,8 @@ struct vo_frame *vo_frame_ref(struct vo_frame *frame)
|
|||
struct vo_frame *new = talloc_ptrtype(NULL, new);
|
||||
talloc_set_destructor(new, destroy_frame);
|
||||
*new = *frame;
|
||||
for (int n = 0; n < frame->num_frames; n++) {
|
||||
for (int n = 0; n < frame->num_frames; n++)
|
||||
new->frames[n] = mp_image_new_ref(frame->frames[n]);
|
||||
MP_HANDLE_OOM(new->frames[n]);
|
||||
}
|
||||
new->current = new->num_frames ? new->frames[0] : NULL;
|
||||
return new;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue