Skip to content

Commit

Permalink
recorder: fix a couple of memory leaks
Browse files Browse the repository at this point in the history
Not sure how long these have been around but it leaked on every packet.
  • Loading branch information
Dudemanguy committed Sep 26, 2023
1 parent b4260be commit 5638fca
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions common/recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ struct mp_recorder_sink {
static int add_stream(struct mp_recorder *priv, struct sh_stream *sh)
{
enum AVMediaType av_type = mp_to_av_stream_type(sh->type);
int ret = -1;
AVCodecParameters *avp = NULL;
if (av_type == AVMEDIA_TYPE_UNKNOWN)
return -1;
goto done;

struct mp_recorder_sink *rst = talloc(priv, struct mp_recorder_sink);
*rst = (struct mp_recorder_sink) {
Expand All @@ -88,11 +90,11 @@ static int add_stream(struct mp_recorder *priv, struct sh_stream *sh)
};

if (!rst->av_stream || !rst->avpkt)
return -1;
goto done;

AVCodecParameters *avp = mp_codec_params_to_av(sh->codec);
avp = mp_codec_params_to_av(sh->codec);
if (!avp)
return -1;
goto done;

// Check if we get the same codec_id for the output format;
// otherwise clear it to have a chance at muxing
Expand All @@ -108,15 +110,20 @@ static int add_stream(struct mp_recorder *priv, struct sh_stream *sh)
avp->video_delay = 16;

if (avp->codec_id == AV_CODEC_ID_NONE)
return -1;
goto done;

if (avcodec_parameters_copy(rst->av_stream->codecpar, avp) < 0)
return -1;
goto done;

ret = 0;
rst->av_stream->time_base = mp_get_codec_timebase(sh->codec);

MP_TARRAY_APPEND(priv, priv->streams, priv->num_streams, rst);
return 0;

done:
if (avp)
avcodec_parameters_free(&avp);
return ret;
}

struct mp_recorder *mp_recorder_create(struct mpv_global *global,
Expand Down Expand Up @@ -254,6 +261,8 @@ static void mux_packet(struct mp_recorder_sink *rst,

if (av_interleaved_write_frame(priv->mux, new_packet) < 0)
MP_ERR(priv, "Failed writing packet.\n");

av_packet_free(&new_packet);
}

// Write all packets available in the stream queue
Expand Down

0 comments on commit 5638fca

Please sign in to comment.