Skip to content

Commit

Permalink
Revisit memory deallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Aug 8, 2024
1 parent f1d9e2f commit 56f1f5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions c_src/xav/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ int decoder_decode(struct Decoder *decoder, AVPacket *pkt, AVFrame *frame) {
}

void decoder_free_frame(struct Decoder *decoder) {
// TODO revisit this
av_frame_unref(decoder->frame);
av_packet_unref(decoder->pkt);
if (decoder->frame != NULL) {
av_frame_unref(decoder->frame);
}
if (decoder->pkt != NULL) {
av_packet_unref(decoder->pkt);
}
}

void decoder_free(struct Decoder **decoder) {
Expand Down
6 changes: 5 additions & 1 deletion c_src/xav/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ int reader_next_frame(struct Reader *reader) {
return 0;
}

void reader_free_frame(struct Reader *reader) { av_frame_unref(reader->frame); }
void reader_free_frame(struct Reader *reader) {
if (reader->frame != NULL) {
av_frame_unref(reader->frame);
}
}

void reader_free(struct Reader **reader) {
XAV_LOG_DEBUG("Freeing Reader object");
Expand Down

0 comments on commit 56f1f5c

Please sign in to comment.