From 0327ccb562666fb6bb025bba21a628d12df1ded1 Mon Sep 17 00:00:00 2001 From: Daniel Morandini Date: Mon, 13 Nov 2023 12:19:35 +0100 Subject: [PATCH] Work on mem leaks --- c_src/Makefile | 2 +- c_src/decoder.c | 3 ++- c_src/libav.c | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/c_src/Makefile b/c_src/Makefile index cbea621..6a1e27d 100644 --- a/c_src/Makefile +++ b/c_src/Makefile @@ -4,7 +4,7 @@ # This works on rtx enabled machines. It is for direct usage only (dev). ifndef ERTS_INCLUDE_DIR -ERTS_INCLUDE_DIR := $(shell rtx where erlang)/erts-14.0.2/include +ERTS_INCLUDE_DIR := $(shell rtx where erlang)/erts-14.1.1/include endif ifndef MIX_APP_PATH MIX_APP_PATH := .. diff --git a/c_src/decoder.c b/c_src/decoder.c index 5282962..7edb0e3 100644 --- a/c_src/decoder.c +++ b/c_src/decoder.c @@ -106,7 +106,8 @@ int decoder_read_frame(Decoder *ctx, AVFrame *frame) { resampled_frame->pts = next_pts; av_frame_unref(frame); - av_frame_ref(frame, resampled_frame); + av_frame_move_ref(frame, resampled_frame); + av_frame_free(&resampled_frame); } return 0; diff --git a/c_src/libav.c b/c_src/libav.c index 2e6ce34..2bd2ee7 100644 --- a/c_src/libav.c +++ b/c_src/libav.c @@ -350,6 +350,9 @@ ERL_NIF_TERM enif_decoder_add_data(ErlNifEnv *env, int argc, if ((errn = decoder_send_packet(ctx, packet)) != 0) return enif_make_av_error(env, errn); + if (packet) + av_packet_unref(packet); + list = enif_make_list(env, 0); if (!(frame = av_frame_alloc())) return enif_make_av_error(env, AVERROR(ENOMEM)); @@ -376,7 +379,7 @@ ERL_NIF_TERM enif_decoder_add_data(ErlNifEnv *env, int argc, // Reset the frame to reuse it for the next decode round. av_frame_unref(frame); } - av_frame_unref(frame); + av_frame_free(&frame); switch (errn) { case 0: