Skip to content

Commit

Permalink
common: ensure MP_HANDLE_OOM is used only on pointers
Browse files Browse the repository at this point in the history
To make it clear it should be used for memory allocation and not generic
error checking.
  • Loading branch information
kasper93 authored and jeeb committed Nov 30, 2024
1 parent 7b114d7 commit d673356
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion audio/decode/ad_lavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ static bool init(struct mp_filter *da, struct mp_codec_params *codec,
}

ctx->avctx = avcodec_alloc_context3(lavc_codec);
MP_HANDLE_OOM(ctx->avctx);
ctx->avframe = av_frame_alloc();
MP_HANDLE_OOM(ctx->avframe);
ctx->avpkt = av_packet_alloc();
MP_HANDLE_OOM(ctx->avctx && ctx->avframe && ctx->avpkt);
MP_HANDLE_OOM(ctx->avpkt);
ctx->avctx->codec_type = AVMEDIA_TYPE_AUDIO;
ctx->avctx->codec_id = lavc_codec->id;
ctx->avctx->pkt_timebase = ctx->codec_timebase;
Expand Down
5 changes: 3 additions & 2 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ char **mp_dup_str_array(void *tctx, char **s);
// This macro generally behaves like an assert(), except it will make sure to
// kill the process even with NDEBUG.
#define MP_HANDLE_OOM(x) do { \
assert(x); \
if (!(x)) \
void *oom_p_ = (x); \
assert(oom_p_); \
if (!oom_p_) \
abort(); \
} while (0)

Expand Down
2 changes: 1 addition & 1 deletion common/encode_lavc.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ static void encode_lavc_add_stream(struct encoder_context *enc,
dst->st->sample_aspect_ratio = info->codecpar->sample_aspect_ratio;

if (avcodec_parameters_copy(dst->st->codecpar, info->codecpar) < 0)
MP_HANDLE_OOM(0);
MP_HANDLE_OOM(NULL);

dst->on_ready = on_ready;
dst->on_ready_ctx = on_ready_ctx;
Expand Down

0 comments on commit d673356

Please sign in to comment.