Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dolby/ac4 memory leak fix #982

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions Source/C++/Codecs/Ap4Ac4Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,17 @@ AP4_Ac4Header::AP4_Ac4Header(const AP4_UI08* bytes, unsigned int size)
AP4_Ac4Header::~AP4_Ac4Header()
{
if (m_PresentationV1) {
bool removed_ss[32];
AP4_SetMemory(removed_ss, false, sizeof(removed_ss));
assert(m_PresentationV1 != NULL);
for (unsigned int pres_idx = 0; pres_idx < m_NPresentations; pres_idx++) {
assert(m_PresentationV1[pres_idx].d.v1.substream_groups != NULL);
for (int j = 0; j < m_PresentationV1[pres_idx].d.v1.n_substream_groups; j++)
delete[] m_PresentationV1[pres_idx].d.v1.substream_groups[j].d.v1.substreams;
if (removed_ss[m_PresentationV1[pres_idx].d.v1.substream_groups[j].d.v1.substreams->ss_idx]) break;
else{
removed_ss[m_PresentationV1[pres_idx].d.v1.substream_groups[j].d.v1.substreams->ss_idx] = true;
delete[] m_PresentationV1[pres_idx].d.v1.substream_groups[j].d.v1.substreams;
}
delete[] m_PresentationV1[pres_idx].d.v1.substream_groups;
delete[] m_PresentationV1[pres_idx].d.v1.substream_group_indexs;
}
Expand Down Expand Up @@ -494,7 +500,35 @@ AP4_Ac4Parser::FindFrame(AP4_Ac4Frame& frame)
frame.m_Info.m_Ac4Dsi.d.v1.ac4_bitrate_dsi.bit_rate = 0; // unknown, fixed value now
frame.m_Info.m_Ac4Dsi.d.v1.ac4_bitrate_dsi.bit_rate_precision = 0xffffffff; // unknown, fixed value now
frame.m_Info.m_Ac4Dsi.d.v1.n_presentations = ac4_header.m_NPresentations;
frame.m_Info.m_Ac4Dsi.d.v1.presentations = ac4_header.m_PresentationV1;

if (ac4_header.m_PresentationV1) {
assert(ac4_header.m_PresentationV1 != NULL);
frame.m_Info.m_Ac4Dsi.d.v1.presentations = new AP4_Dac4Atom::Ac4Dsi::PresentationV1[ac4_header.m_NPresentations];
AP4_CopyMemory(frame.m_Info.m_Ac4Dsi.d.v1.presentations,
ac4_header.m_PresentationV1,
sizeof(AP4_Dac4Atom::Ac4Dsi::PresentationV1) * ac4_header.m_NPresentations);
for (unsigned int pres_idx = 0; pres_idx < ac4_header.m_NPresentations; pres_idx++) {
assert(ac4_header.m_PresentationV1[pres_idx].d.v1.substream_groups != NULL);
int n_substream_group = ac4_header.m_PresentationV1[pres_idx].d.v1.n_substream_groups;
frame.m_Info.m_Ac4Dsi.d.v1.presentations[pres_idx].d.v1.substream_groups = new AP4_Dac4Atom::Ac4Dsi::SubStreamGroupV1[n_substream_group];
frame.m_Info.m_Ac4Dsi.d.v1.presentations[pres_idx].d.v1.substream_group_indexs = new AP4_UI32[n_substream_group];
AP4_CopyMemory(frame.m_Info.m_Ac4Dsi.d.v1.presentations[pres_idx].d.v1.substream_group_indexs,
ac4_header.m_PresentationV1[pres_idx].d.v1.substream_group_indexs,
sizeof(AP4_UI32)*n_substream_group);
AP4_CopyMemory(frame.m_Info.m_Ac4Dsi.d.v1.presentations[pres_idx].d.v1.substream_groups,
ac4_header.m_PresentationV1[pres_idx].d.v1.substream_groups,
sizeof(AP4_Dac4Atom::Ac4Dsi::SubStreamGroupV1)*n_substream_group);
for (unsigned int sg_idx = 0; sg_idx < n_substream_group; sg_idx++) {
assert(ac4_header.m_PresentationV1[pres_idx].d.v1.substream_groups[sg_idx].d.v1.substreams != NULL);
int n_substreams = ac4_header.m_PresentationV1[pres_idx].d.v1.substream_groups[sg_idx].d.v1.n_substreams;
frame.m_Info.m_Ac4Dsi.d.v1.presentations[pres_idx].d.v1.substream_groups[sg_idx].d.v1.substreams
= new AP4_Dac4Atom::Ac4Dsi::SubStream[n_substreams];
AP4_CopyMemory(frame.m_Info.m_Ac4Dsi.d.v1.presentations[pres_idx].d.v1.substream_groups[sg_idx].d.v1.substreams,
ac4_header.m_PresentationV1[pres_idx].d.v1.substream_groups[sg_idx].d.v1.substreams,
sizeof(AP4_Dac4Atom::Ac4Dsi::SubStream) * n_substreams);
}
}
}

/* set the frame source */
frame.m_Source = &m_Bits;
Expand Down
2 changes: 1 addition & 1 deletion Source/C++/Core/Ap4Dac4Atom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ AP4_Dac4Atom::Ac4Dsi::SubStream::ParseSubstreamIdxInfo(AP4_BitReader &bits, unsi
{
if (b_substreams_present == 1) {
if (bits.ReadBits(2) == 3) { // substream_index
AP4_Ac4VariableBits(bits, 2);
ss_idx = AP4_Ac4VariableBits(bits, 2);
}
}
return AP4_SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions Source/C++/Core/Ap4Dac4Atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class AP4_Dac4Atom : public AP4_Atom
AP4_UI08 b_substream_contains_bed_objects;
AP4_UI08 b_substream_contains_dynamic_objects;
AP4_UI08 b_substream_contains_ISF_objects;
AP4_UI08 ss_idx;

// methods
AP4_Result ParseSubstreamInfoChan(AP4_BitReader &bits,
Expand Down
Loading