Skip to content

Commit

Permalink
Work on mem leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorn committed Nov 13, 2023
1 parent 3840cb9 commit 0327ccb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion c_src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ..
Expand Down
3 changes: 2 additions & 1 deletion c_src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion c_src/libav.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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:
Expand Down

0 comments on commit 0327ccb

Please sign in to comment.