Fix memory leaks from errors skipping resource release. v7.0.32 (#4308)

---------

Co-authored-by: winlin <winlinvip@gmail.com>
Co-authored-by: john <hondaxiao@tencent.com>

---------

Co-authored-by: john <hondaxiao@tencent.com>
This commit is contained in:
Haibo Chen(陈海博) 2025-04-30 12:09:31 +08:00 committed by GitHub
parent 3fbd609bc7
commit e00937e387
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 6 deletions

View File

@ -7,6 +7,7 @@ The changelog for SRS.
<a name="v7-changes"></a>
## SRS 7.0 Changelog
* v7.0, 2025-04-30, Merge [#4308](https://github.com/ossrs/srs/pull/4308): Fix memory leaks from errors skipping resource release. v7.0.32 (#4308)
* v7.0, 2025-04-26, Merge [#4292](https://github.com/ossrs/srs/pull/4309): Support custom deleter for SrsUniquePtr. v7.0.31 (#4309)
* v7.0, 2025-03-21, Merge [#4292](https://github.com/ossrs/srs/pull/4292): Typo: "forked" process in log output. v7.0.30 (#4292)
* v7.0, 2025-03-21, Merge [#4294](https://github.com/ossrs/srs/pull/4294): Build: update build version to v7. v7.0.29 (#4294)

View File

@ -1045,6 +1045,15 @@ srs_error_t SrsRtcRtpBuilder::package_opus(SrsAudioFrame* audio, SrsRtpPacket* p
return err;
}
static void free_packets(vector<SrsRtpPacket*>* pkts) {
if (!pkts) return;
for (size_t i = 0; i < pkts->size(); i++) {
srs_freep((*pkts)[i]);
}
pkts->clear();
}
srs_error_t SrsRtcRtpBuilder::on_video(SrsSharedPtrMessage* msg)
{
srs_error_t err = srs_success;
@ -1094,6 +1103,9 @@ srs_error_t SrsRtcRtpBuilder::on_video(SrsSharedPtrMessage* msg)
// If merge Nalus, we pcakges all NALUs(samples) as one NALU, in a RTP or FUA packet.
vector<SrsRtpPacket*> pkts;
// auto free when exit
SrsUniquePtr<vector<SrsRtpPacket*>> pkts_ptr(&pkts, free_packets);
if (merge_nalus && nn_samples > 1) {
if ((err = package_nalus(msg, samples, pkts)) != srs_success) {
return srs_error_wrap(err, "package nalus as one");
@ -1393,11 +1405,6 @@ srs_error_t SrsRtcRtpBuilder::consume_packets(vector<SrsRtpPacket*>& pkts)
}
}
for (int i = 0; i < (int)pkts.size(); i++) {
SrsRtpPacket* pkt = pkts[i];
srs_freep(pkt);
}
return err;
}

View File

@ -9,6 +9,6 @@
#define VERSION_MAJOR 7
#define VERSION_MINOR 0
#define VERSION_REVISION 31
#define VERSION_REVISION 32
#endif