Skip to content

Commit

Permalink
Fixed memory leak in bitstream analyze stage
Browse files Browse the repository at this point in the history
  • Loading branch information
BykadorovR committed Oct 28, 2019
1 parent db7b55c commit 968b646
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docker/Dockerfile_cu10
Expand Up @@ -37,7 +37,8 @@ RUN git clone --depth 1 -b release/4.2 --single-branch https://github.com/FFmpeg
RUN pip3 install --no-cache-dir \
twine==1.13.0 \
awscli==1.16.194 \
numpy==1.16.4
numpy==1.16.4 \
packaging

# Install PyTorch
RUN pip3 install --no-cache-dir \
Expand Down
2 changes: 1 addition & 1 deletion include/Parser.h
Expand Up @@ -152,7 +152,7 @@ class Parser {
Bitstream filter for converting mp4->h264
*/
AVBitStreamFilterContext* bitstreamFilter;
std::shared_ptr<AVPacket> NALu;
AVPacket* NALu;
/*
Instance of Logger class
*/
Expand Down
12 changes: 11 additions & 1 deletion src/Parser.cpp
Expand Up @@ -276,6 +276,10 @@ int Parser::Analyze(AVPacket* package) {
frameNumValue = frame_num;
POC = pic_order_cnt_lsb;
}

av_freep(&NALu->data);
av_packet_free_side_data(NALu);
av_free_packet(NALu);
return errorBitstream;
}

Expand Down Expand Up @@ -310,7 +314,9 @@ int Parser::Init(ParserParameters& input, std::shared_ptr<Logger> logger) {
//Write file header
sts = avformat_write_header(dumpContext, NULL);
}
NALu = std::make_shared<AVPacket>();
NALu = new AVPacket();
av_init_packet(NALu);

bitstreamFilter = av_bitstream_filter_init("h264_mp4toannexb");

lastFrame = std::make_pair(new AVPacket(), false);
Expand Down Expand Up @@ -402,5 +408,9 @@ void Parser::Close() {
}
av_packet_unref(lastFrame.first);
delete lastFrame.first;

av_packet_unref(NALu);
delete NALu;

isClosed = true;
}

0 comments on commit 968b646

Please sign in to comment.