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

Fix stack overflow and memory leak when running tests #1120

Closed
wants to merge 6 commits into from

Conversation

satoren
Copy link
Contributor

@satoren satoren commented Jul 14, 2023

I didn't know how to find the buffer size of the packet, so I added free buffer as I did for the other tests.

@ibc
Copy link
Member

ibc commented Jul 17, 2023

It makes sense. Just let's us review this during this week, please.

@ibc ibc requested review from ibc, jmillan and nazar-pc July 17, 2023 17:46
@@ -502,6 +503,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might have been beneficial to expand comment on why extra buffer is needed and maybe have buffer size be a fixed size array calculate statically, otherwise this seems to be somewhat accidental that it works at all. In other tests you've set buffer to 1500 bytes, but not here.

Copy link
Contributor Author

@satoren satoren Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, but I don't know how the buffer size is calculated.

Copy link
Member

@jmillan jmillan Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other tests you've set buffer to 1500 bytes, but not here.

Yes, let's be consistent and just define the buffer length rather than adding this extra zeroes please.

@@ -28,15 +28,15 @@ class RtpMyRetransmissionBuffer : public RtpRetransmissionBuffer
void Insert(uint16_t seq, uint32_t timestamp)
{
// clang-format off
uint8_t rtpBuffer[] =
uint8_t rtpBuffer[1500] =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need to be this large, is there a way to calculate it from some constant rather than using a magic constant here?

@@ -57,7 +57,7 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]")
packet1->Serialize(bufferPacket1);

// Create a new packet out of the external buffer.
auto packet2 = ExtendedReportPacket::Parse(bufferPacket1, packet1->GetSize());
auto packet2 = std::unique_ptr<ExtendedReportPacket>(ExtendedReportPacket::Parse(bufferPacket1, packet1->GetSize()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Parse returns heap-allocated data structure. I think we should change auto to auto* to make that clearer and just call delete at the end for consistency.

We can also use std::unique_ptr, which I guess will be beneficial due to not leaking memory even when test fails, but then we might want to use it in all other tests too consistently.

@@ -665,6 +667,8 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, please define the correct length to the array rather than adding this extra zeroes.

@satoren
Copy link
Contributor Author

satoren commented Apr 16, 2024

Duplicated with #1318

@satoren satoren closed this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants