Support address sanitizer for utest and fix some leaks. (#3242)

* MP4: Fix memory leak when error.

* Kernel: Support free global objects for utest.

* HTTP: Fix memory leak when error.

* MP4: Support more sample rate for audio.

* RTMP: Support free field for utest.

* UTest: Support address sanitizer.
pull/3246/head
Winlin 2 years ago committed by GitHub
parent be0241efdb
commit 368356c223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -59,6 +59,13 @@ SrsResourceManager::~SrsResourceManager()
clear(); clear();
// Free all objects not in zombies.
std::vector<ISrsResource*>::iterator it;
for (it = conns_.begin(); it != conns_.end(); ++it) {
ISrsResource* resource = *it;
srs_freep(resource);
}
srs_freepa(conns_level0_cache_); srs_freepa(conns_level0_cache_);
} }

@ -68,6 +68,61 @@ string srs_audio_codec_id2str(SrsAudioCodecId codec)
} }
} }
SrsAudioSampleRate srs_audio_sample_rate_from_number(uint32_t v)
{
if (v == 5512) return SrsAudioSampleRate5512;
if (v == 11025) return SrsAudioSampleRate11025;
if (v == 22050) return SrsAudioSampleRate22050;
if (v == 44100) return SrsAudioSampleRate44100;
if (v == 12000) return SrsAudioSampleRate12000;
if (v == 24000) return SrsAudioSampleRate24000;
if (v == 48000) return SrsAudioSampleRate48000;
if (v == 8000) return SrsAudioSampleRateNB8kHz;
if (v == 12000) return SrsAudioSampleRateMB12kHz;
if (v == 16000) return SrsAudioSampleRateWB16kHz;
if (v == 24000) return SrsAudioSampleRateSWB24kHz;
if (v == 48000) return SrsAudioSampleRateFB48kHz;
return SrsAudioSampleRateForbidden;
}
SrsAudioSampleRate srs_audio_sample_rate_guess_number(uint32_t v)
{
if (v >= 48000) return SrsAudioSampleRate48000;
if (v >= 44100) return SrsAudioSampleRate44100;
if (v >= 24000) return SrsAudioSampleRate24000;
if (v >= 24000) return SrsAudioSampleRate24000;
if (v >= 22050) return SrsAudioSampleRate22050;
if (v >= 16000) return SrsAudioSampleRateWB16kHz;
if (v >= 12000) return SrsAudioSampleRate12000;
if (v >= 8000) return SrsAudioSampleRateNB8kHz;
if (v >= 5512) return SrsAudioSampleRate5512;
return SrsAudioSampleRateForbidden;
}
uint32_t srs_audio_sample_rate2number(SrsAudioSampleRate v)
{
if (v == SrsAudioSampleRate5512) return 5512;
if (v == SrsAudioSampleRate11025) return 11025;
if (v == SrsAudioSampleRate22050) return 22050;
if (v == SrsAudioSampleRate44100) return 44100;
if (v == SrsAudioSampleRate12000) return 12000;
if (v == SrsAudioSampleRate24000) return 24000;
if (v == SrsAudioSampleRate48000) return 48000;
if (v == SrsAudioSampleRateNB8kHz) return 8000;
if (v == SrsAudioSampleRateMB12kHz) return 12000;
if (v == SrsAudioSampleRateWB16kHz) return 16000;
if (v == SrsAudioSampleRateSWB24kHz) return 24000;
if (v == SrsAudioSampleRateFB48kHz) return 48000;
return 0;
}
string srs_audio_sample_rate2str(SrsAudioSampleRate v) string srs_audio_sample_rate2str(SrsAudioSampleRate v)
{ {
switch (v) { switch (v) {

@ -196,6 +196,11 @@ enum SrsAudioSampleRate
SrsAudioSampleRate11025 = 1, SrsAudioSampleRate11025 = 1,
SrsAudioSampleRate22050 = 2, SrsAudioSampleRate22050 = 2,
SrsAudioSampleRate44100 = 3, SrsAudioSampleRate44100 = 3,
// For MP4, extra sampling rate to FLV.
SrsAudioSampleRate12000 = 12,
SrsAudioSampleRate24000 = 24,
SrsAudioSampleRate48000 = 48,
// For Opus, support 8, 12, 16, 24, 48KHz // For Opus, support 8, 12, 16, 24, 48KHz
// We will write a UINT8 sampling rate after FLV audio tag header. // We will write a UINT8 sampling rate after FLV audio tag header.
@ -206,6 +211,9 @@ enum SrsAudioSampleRate
SrsAudioSampleRateSWB24kHz = 24, // SWB (super-wideband) SrsAudioSampleRateSWB24kHz = 24, // SWB (super-wideband)
SrsAudioSampleRateFB48kHz = 48, // FB (fullband) SrsAudioSampleRateFB48kHz = 48, // FB (fullband)
}; };
SrsAudioSampleRate srs_audio_sample_rate_from_number(uint32_t v);
SrsAudioSampleRate srs_audio_sample_rate_guess_number(uint32_t v);
uint32_t srs_audio_sample_rate2number(SrsAudioSampleRate v);
std::string srs_audio_sample_rate2str(SrsAudioSampleRate v); std::string srs_audio_sample_rate2str(SrsAudioSampleRate v);
/** /**

@ -5237,6 +5237,8 @@ srs_error_t SrsMp4BoxReader::read(SrsSimpleStream* stream, SrsMp4Box** ppbox)
srs_error_t err = srs_success; srs_error_t err = srs_success;
SrsMp4Box* box = NULL; SrsMp4Box* box = NULL;
SrsAutoFree(SrsMp4Box, box);
while (true) { while (true) {
// For the first time to read the box, maybe it's a basic box which is only 4bytes header. // For the first time to read the box, maybe it's a basic box which is only 4bytes header.
// When we disconvery the real box, we know the size of the whole box, then read again and decode it. // When we disconvery the real box, we know the size of the whole box, then read again and decode it.
@ -5277,10 +5279,9 @@ srs_error_t SrsMp4BoxReader::read(SrsSimpleStream* stream, SrsMp4Box** ppbox)
continue; continue;
} }
if (err != srs_success) { if (err == srs_success) {
srs_freep(box);
} else {
*ppbox = box; *ppbox = box;
box = NULL;
} }
break; break;
@ -5352,6 +5353,7 @@ srs_error_t SrsMp4Decoder::initialize(ISrsReadSeeker* rs)
while (true) { while (true) {
SrsMp4Box* box = NULL; SrsMp4Box* box = NULL;
SrsAutoFree(SrsMp4Box, box);
if ((err = load_next_box(&box, 0)) != srs_success) { if ((err = load_next_box(&box, 0)) != srs_success) {
return srs_error_wrap(err, "load box"); return srs_error_wrap(err, "load box");
@ -5375,8 +5377,6 @@ srs_error_t SrsMp4Decoder::initialize(ISrsReadSeeker* rs)
} }
break; break;
} }
srs_freep(box);
} }
if (brand == SrsMp4BoxBrandForbidden) { if (brand == SrsMp4BoxBrandForbidden) {
@ -5508,14 +5508,8 @@ srs_error_t SrsMp4Decoder::parse_moov(SrsMp4MovieBox* moov)
SrsMp4AudioSampleEntry* mp4a = soun? soun->mp4a():NULL; SrsMp4AudioSampleEntry* mp4a = soun? soun->mp4a():NULL;
if (mp4a) { if (mp4a) {
uint32_t sr = mp4a->samplerate>>16; uint32_t sr = mp4a->samplerate>>16;
if (sr >= 44100) { if ((sample_rate = srs_audio_sample_rate_from_number(sr)) == SrsAudioSampleRateForbidden) {
sample_rate = SrsAudioSampleRate44100; sample_rate = srs_audio_sample_rate_guess_number(sr);
} else if (sr >= 22050) {
sample_rate = SrsAudioSampleRate22050;
} else if (sr >= 11025) {
sample_rate = SrsAudioSampleRate11025;
} else {
sample_rate = SrsAudioSampleRate5512;
} }
if (mp4a->samplesize == 16) { if (mp4a->samplesize == 16) {
@ -5580,16 +5574,17 @@ srs_error_t SrsMp4Decoder::load_next_box(SrsMp4Box** ppbox, uint32_t required_bo
while (true) { while (true) {
SrsMp4Box* box = NULL; SrsMp4Box* box = NULL;
SrsAutoFree(SrsMp4Box, box);
if ((err = do_load_next_box(&box, required_box_type)) != srs_success) { if ((err = do_load_next_box(&box, required_box_type)) != srs_success) {
srs_freep(box);
return srs_error_wrap(err, "load box"); return srs_error_wrap(err, "load box");
} }
if (!required_box_type || (uint32_t)box->type == required_box_type) { if (!required_box_type || (uint32_t)box->type == required_box_type) {
*ppbox = box; *ppbox = box;
box = NULL;
break; break;
} }
srs_freep(box);
} }
return err; return err;
@ -5938,7 +5933,7 @@ srs_error_t SrsMp4Encoder::flush()
SrsMp4AudioSampleEntry* mp4a = new SrsMp4AudioSampleEntry(); SrsMp4AudioSampleEntry* mp4a = new SrsMp4AudioSampleEntry();
mp4a->data_reference_index = 1; mp4a->data_reference_index = 1;
mp4a->samplerate = uint32_t(srs_flv_srates[sample_rate]) << 16; mp4a->samplerate = srs_audio_sample_rate2number(sample_rate);
if (sound_bits == SrsAudioSampleBits16bit) { if (sound_bits == SrsAudioSampleBits16bit) {
mp4a->samplesize = 16; mp4a->samplesize = 16;
} else { } else {
@ -6101,7 +6096,7 @@ SrsMp4ObjectType SrsMp4Encoder::get_audio_object_type()
case SrsAudioCodecIdAAC: case SrsAudioCodecIdAAC:
return SrsMp4ObjectTypeAac; return SrsMp4ObjectTypeAac;
case SrsAudioCodecIdMP3: case SrsAudioCodecIdMP3:
return (srs_flv_srates[sample_rate] > 24000) ? SrsMp4ObjectTypeMp1a : SrsMp4ObjectTypeMp3; // 11172 - 3 return (srs_audio_sample_rate2number(sample_rate) > 24000) ? SrsMp4ObjectTypeMp1a : SrsMp4ObjectTypeMp3; // 11172 - 3
default: default:
return SrsMp4ObjectTypeForbidden; return SrsMp4ObjectTypeForbidden;
} }

@ -689,12 +689,14 @@ srs_error_t SrsHttpServeMux::handle(std::string pattern, ISrsHttpHandler* handle
srs_assert(handler); srs_assert(handler);
if (pattern.empty()) { if (pattern.empty()) {
srs_freep(handler);
return srs_error_new(ERROR_HTTP_PATTERN_EMPTY, "empty pattern"); return srs_error_new(ERROR_HTTP_PATTERN_EMPTY, "empty pattern");
} }
if (entries.find(pattern) != entries.end()) { if (entries.find(pattern) != entries.end()) {
SrsHttpMuxEntry* exists = entries[pattern]; SrsHttpMuxEntry* exists = entries[pattern];
if (exists->explicit_match) { if (exists->explicit_match) {
srs_freep(handler);
return srs_error_new(ERROR_HTTP_PATTERN_DUPLICATED, "pattern=%s exists", pattern.c_str()); return srs_error_new(ERROR_HTTP_PATTERN_DUPLICATED, "pattern=%s exists", pattern.c_str());
} }
} }

@ -3331,6 +3331,12 @@ SrsCreateStreamPacket::~SrsCreateStreamPacket()
srs_freep(command_object); srs_freep(command_object);
} }
void SrsCreateStreamPacket::set_command_object(SrsAmf0Any* v)
{
srs_freep(command_object);
command_object = v;
}
srs_error_t SrsCreateStreamPacket::decode(SrsBuffer* stream) srs_error_t SrsCreateStreamPacket::decode(SrsBuffer* stream)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -3509,6 +3515,12 @@ SrsFMLEStartPacket::~SrsFMLEStartPacket()
srs_freep(command_object); srs_freep(command_object);
} }
void SrsFMLEStartPacket::set_command_object(SrsAmf0Any* v)
{
srs_freep(command_object);
command_object = v;
}
srs_error_t SrsFMLEStartPacket::decode(SrsBuffer* stream) srs_error_t SrsFMLEStartPacket::decode(SrsBuffer* stream)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -3613,6 +3625,18 @@ SrsFMLEStartResPacket::~SrsFMLEStartResPacket()
srs_freep(args); srs_freep(args);
} }
void SrsFMLEStartResPacket::set_args(SrsAmf0Any* v)
{
srs_freep(args);
args = v;
}
void SrsFMLEStartResPacket::set_command_object(SrsAmf0Any* v)
{
srs_freep(command_object);
command_object = v;
}
srs_error_t SrsFMLEStartResPacket::decode(SrsBuffer* stream) srs_error_t SrsFMLEStartResPacket::decode(SrsBuffer* stream)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -3691,6 +3715,12 @@ SrsPublishPacket::~SrsPublishPacket()
srs_freep(command_object); srs_freep(command_object);
} }
void SrsPublishPacket::set_command_object(SrsAmf0Any* v)
{
srs_freep(command_object);
command_object = v;
}
srs_error_t SrsPublishPacket::decode(SrsBuffer* stream) srs_error_t SrsPublishPacket::decode(SrsBuffer* stream)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -3961,6 +3991,18 @@ SrsPlayResPacket::~SrsPlayResPacket()
srs_freep(desc); srs_freep(desc);
} }
void SrsPlayResPacket::set_command_object(SrsAmf0Any* v)
{
srs_freep(command_object);
command_object = v;
}
void SrsPlayResPacket::set_desc(SrsAmf0Object* v)
{
srs_freep(desc);
desc = v;
}
int SrsPlayResPacket::get_prefer_cid() int SrsPlayResPacket::get_prefer_cid()
{ {
return RTMP_CID_OverStream; return RTMP_CID_OverStream;
@ -4012,6 +4054,12 @@ SrsOnBWDonePacket::~SrsOnBWDonePacket()
srs_freep(args); srs_freep(args);
} }
void SrsOnBWDonePacket::set_args(SrsAmf0Any* v)
{
srs_freep(args);
args = v;
}
int SrsOnBWDonePacket::get_prefer_cid() int SrsOnBWDonePacket::get_prefer_cid()
{ {
return RTMP_CID_OverConnection; return RTMP_CID_OverConnection;
@ -4061,6 +4109,18 @@ SrsOnStatusCallPacket::~SrsOnStatusCallPacket()
srs_freep(data); srs_freep(data);
} }
void SrsOnStatusCallPacket::set_args(SrsAmf0Any* v)
{
srs_freep(args);
args = v;
}
void SrsOnStatusCallPacket::set_data(SrsAmf0Object* v)
{
srs_freep(data);
data = v;
}
int SrsOnStatusCallPacket::get_prefer_cid() int SrsOnStatusCallPacket::get_prefer_cid()
{ {
return RTMP_CID_OverStream; return RTMP_CID_OverStream;
@ -4111,6 +4171,12 @@ SrsOnStatusDataPacket::~SrsOnStatusDataPacket()
srs_freep(data); srs_freep(data);
} }
void SrsOnStatusDataPacket::set_data(SrsAmf0Object* v)
{
srs_freep(data);
data = v;
}
int SrsOnStatusDataPacket::get_prefer_cid() int SrsOnStatusDataPacket::get_prefer_cid()
{ {
return RTMP_CID_OverStream; return RTMP_CID_OverStream;
@ -4198,6 +4264,12 @@ SrsOnMetaDataPacket::~SrsOnMetaDataPacket()
srs_freep(metadata); srs_freep(metadata);
} }
void SrsOnMetaDataPacket::set_metadata(SrsAmf0Object* v)
{
srs_freep(metadata);
metadata = v;
}
srs_error_t SrsOnMetaDataPacket::decode(SrsBuffer* stream) srs_error_t SrsOnMetaDataPacket::decode(SrsBuffer* stream)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;

@ -908,6 +908,8 @@ public:
public: public:
SrsCreateStreamPacket(); SrsCreateStreamPacket();
virtual ~SrsCreateStreamPacket(); virtual ~SrsCreateStreamPacket();
public:
void set_command_object(SrsAmf0Any* v);
// Decode functions for concrete packet to override. // Decode functions for concrete packet to override.
public: public:
virtual srs_error_t decode(SrsBuffer* stream); virtual srs_error_t decode(SrsBuffer* stream);
@ -982,6 +984,8 @@ public:
public: public:
SrsFMLEStartPacket(); SrsFMLEStartPacket();
virtual ~SrsFMLEStartPacket(); virtual ~SrsFMLEStartPacket();
public:
void set_command_object(SrsAmf0Any* v);
// Decode functions for concrete packet to override. // Decode functions for concrete packet to override.
public: public:
virtual srs_error_t decode(SrsBuffer* stream); virtual srs_error_t decode(SrsBuffer* stream);
@ -1014,6 +1018,9 @@ public:
public: public:
SrsFMLEStartResPacket(double _transaction_id); SrsFMLEStartResPacket(double _transaction_id);
virtual ~SrsFMLEStartResPacket(); virtual ~SrsFMLEStartResPacket();
public:
void set_args(SrsAmf0Any* v);
void set_command_object(SrsAmf0Any* v);
// Decode functions for concrete packet to override. // Decode functions for concrete packet to override.
public: public:
virtual srs_error_t decode(SrsBuffer* stream); virtual srs_error_t decode(SrsBuffer* stream);
@ -1057,6 +1064,8 @@ public:
public: public:
SrsPublishPacket(); SrsPublishPacket();
virtual ~SrsPublishPacket(); virtual ~SrsPublishPacket();
public:
void set_command_object(SrsAmf0Any* v);
// Decode functions for concrete packet to override. // Decode functions for concrete packet to override.
public: public:
virtual srs_error_t decode(SrsBuffer* stream); virtual srs_error_t decode(SrsBuffer* stream);
@ -1181,6 +1190,9 @@ public:
public: public:
SrsPlayResPacket(); SrsPlayResPacket();
virtual ~SrsPlayResPacket(); virtual ~SrsPlayResPacket();
public:
void set_command_object(SrsAmf0Any* v);
void set_desc(SrsAmf0Object* v);
// Encode functions for concrete packet to override. // Encode functions for concrete packet to override.
public: public:
virtual int get_prefer_cid(); virtual int get_prefer_cid();
@ -1204,6 +1216,8 @@ public:
public: public:
SrsOnBWDonePacket(); SrsOnBWDonePacket();
virtual ~SrsOnBWDonePacket(); virtual ~SrsOnBWDonePacket();
public:
void set_args(SrsAmf0Any* v);
// Encode functions for concrete packet to override. // Encode functions for concrete packet to override.
public: public:
virtual int get_prefer_cid(); virtual int get_prefer_cid();
@ -1232,6 +1246,9 @@ public:
public: public:
SrsOnStatusCallPacket(); SrsOnStatusCallPacket();
virtual ~SrsOnStatusCallPacket(); virtual ~SrsOnStatusCallPacket();
public:
void set_args(SrsAmf0Any* v);
void set_data(SrsAmf0Object* v);
// Encode functions for concrete packet to override. // Encode functions for concrete packet to override.
public: public:
virtual int get_prefer_cid(); virtual int get_prefer_cid();
@ -1255,6 +1272,9 @@ public:
public: public:
SrsOnStatusDataPacket(); SrsOnStatusDataPacket();
virtual ~SrsOnStatusDataPacket(); virtual ~SrsOnStatusDataPacket();
public:
void set_data(SrsAmf0Object* v);
SrsAmf0Object* get_data();
// Encode functions for concrete packet to override. // Encode functions for concrete packet to override.
public: public:
virtual int get_prefer_cid(); virtual int get_prefer_cid();
@ -1303,6 +1323,8 @@ public:
public: public:
SrsOnMetaDataPacket(); SrsOnMetaDataPacket();
virtual ~SrsOnMetaDataPacket(); virtual ~SrsOnMetaDataPacket();
public:
void set_metadata(SrsAmf0Object* v);
// Decode functions for concrete packet to override. // Decode functions for concrete packet to override.
public: public:
virtual srs_error_t decode(SrsBuffer* stream); virtual srs_error_t decode(SrsBuffer* stream);

@ -665,6 +665,17 @@ bool srs_net_device_is_internet(const sockaddr* addr)
} }
vector<SrsIPAddress*> _srs_system_ips; vector<SrsIPAddress*> _srs_system_ips;
void srs_free_global_system_ips()
{
vector<SrsIPAddress*>& ips = _srs_system_ips;
// Release previous IPs.
for (int i = 0; i < (int)ips.size(); i++) {
SrsIPAddress* ip = ips[i];
srs_freep(ip);
}
ips.clear();
}
void discover_network_iface(ifaddrs* cur, vector<SrsIPAddress*>& ips, stringstream& ss0, stringstream& ss1, bool ipv6, bool loopback) void discover_network_iface(ifaddrs* cur, vector<SrsIPAddress*>& ips, stringstream& ss0, stringstream& ss1, bool ipv6, bool loopback)
{ {
@ -702,14 +713,10 @@ void discover_network_iface(ifaddrs* cur, vector<SrsIPAddress*>& ips, stringstre
void retrieve_local_ips() void retrieve_local_ips()
{ {
vector<SrsIPAddress*>& ips = _srs_system_ips;
// Release previous IPs. // Release previous IPs.
for (int i = 0; i < (int)ips.size(); i++) { srs_free_global_system_ips();
SrsIPAddress* ip = ips[i];
srs_freep(ip); vector<SrsIPAddress*>& ips = _srs_system_ips;
}
ips.clear();
// Get the addresses. // Get the addresses.
ifaddrs* ifap; ifaddrs* ifap;

@ -81,6 +81,9 @@ srs_error_t prepare_main() {
return err; return err;
} }
// Free global data, for address sanitizer.
extern void srs_free_global_system_ips();
// We could do something in the main of utest. // We could do something in the main of utest.
// Copy from gtest-1.6.0/src/gtest_main.cc // Copy from gtest-1.6.0/src/gtest_main.cc
GTEST_API_ int main(int argc, char **argv) { GTEST_API_ int main(int argc, char **argv) {
@ -97,7 +100,11 @@ GTEST_API_ int main(int argc, char **argv) {
} }
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); int r0 = RUN_ALL_TESTS();
srs_free_global_system_ips();
return r0;
} }
MockEmptyLog::MockEmptyLog(SrsLogLevel l) MockEmptyLog::MockEmptyLog(SrsLogLevel l)

@ -75,7 +75,7 @@ VOID TEST(ProtocolAMF0Test, ScenarioMain)
EXPECT_EQ(0x03, bytes[0]); EXPECT_EQ(0x03, bytes[0]);
EXPECT_EQ(0x09, bytes[nb_bytes - 1]); EXPECT_EQ(0x09, bytes[nb_bytes - 1]);
} }
SrsAutoFree(char, bytes); SrsAutoFreeA(char, bytes);
// decoding amf0 object from bytes // decoding amf0 object from bytes
// when user know the schema // when user know the schema
@ -1301,7 +1301,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesString)
EXPECT_TRUE(string("hello") == pp->to_str()); EXPECT_TRUE(string("hello") == pp->to_str());
// For copy. // For copy.
SrsAmf0Any* cp = p->copy(); SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp);
EXPECT_TRUE(string("hello") == cp->to_str()); EXPECT_TRUE(string("hello") == cp->to_str());
} }
@ -1430,7 +1430,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesBoolean)
EXPECT_FALSE(p->to_boolean()); EXPECT_FALSE(p->to_boolean());
// For copy. // For copy.
SrsAmf0Any* cp = p->copy(); SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp);
EXPECT_FALSE(cp->to_boolean()); EXPECT_FALSE(cp->to_boolean());
} }
@ -1527,7 +1527,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesNumber)
EXPECT_TRUE(100.1 == p->to_number()); EXPECT_TRUE(100.1 == p->to_number());
// For copy. // For copy.
SrsAmf0Any* cp = p->copy(); SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp);
EXPECT_TRUE(100.1 == cp->to_number()); EXPECT_TRUE(100.1 == cp->to_number());
} }
@ -1790,6 +1790,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesObject)
// For copy. // For copy.
SrsAmf0Any* cp = p->copy(); SrsAmf0Any* cp = p->copy();
SrsAutoFree(SrsAmf0Any, cp);
EXPECT_TRUE(NULL != cp->to_object()); EXPECT_TRUE(NULL != cp->to_object());
} }
@ -1992,7 +1993,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesObjectEOF)
HELPER_EXPECT_SUCCESS(pp->read(&b)); HELPER_EXPECT_SUCCESS(pp->read(&b));
// For copy. // For copy.
SrsAmf0Any* cp = p->copy(); SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp);
EXPECT_TRUE(cp->is_object_eof()); EXPECT_TRUE(cp->is_object_eof());
} }
@ -2084,7 +2085,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesEcmaArray)
EXPECT_TRUE(NULL != pp->to_ecma_array()); EXPECT_TRUE(NULL != pp->to_ecma_array());
// For copy. // For copy.
SrsAmf0Any* cp = p->copy(); SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp);
EXPECT_TRUE(NULL != cp->to_ecma_array()); EXPECT_TRUE(NULL != cp->to_ecma_array());
} }
@ -2211,7 +2212,7 @@ VOID TEST(ProtocolAMF0Test, InterfacesStrictArray)
EXPECT_TRUE(NULL != pp->to_strict_array()); EXPECT_TRUE(NULL != pp->to_strict_array());
// For copy. // For copy.
SrsAmf0Any* cp = p->copy(); SrsAmf0Any* cp = p->copy(); SrsAutoFree(SrsAmf0Any, cp);
EXPECT_TRUE(NULL != cp->to_strict_array()); EXPECT_TRUE(NULL != cp->to_strict_array());
} }

@ -222,7 +222,7 @@ VOID TEST(SrsAVCTest, H264IPBFrame)
EXPECT_EQ(SrsVideoAvcFrameTraitSequenceHeader, uint8_t(flv[1])); EXPECT_EQ(SrsVideoAvcFrameTraitSequenceHeader, uint8_t(flv[1]));
EXPECT_EQ(01, flv[2]); EXPECT_EQ(02, flv[3]); EXPECT_EQ(03, flv[4]); EXPECT_EQ(01, flv[2]); EXPECT_EQ(02, flv[3]); EXPECT_EQ(03, flv[4]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+5, 5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+5, 5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
// For muxing I/P/B frame. // For muxing I/P/B frame.
@ -493,7 +493,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
EXPECT_EQ(6, nb_flv); EXPECT_EQ(6, nb_flv);
EXPECT_EQ(0x23, (uint8_t)flv[0]); EXPECT_EQ(0x23, (uint8_t)flv[0]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
// For Opus frame. // For Opus frame.
@ -508,7 +508,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
EXPECT_EQ(6, nb_flv); EXPECT_EQ(6, nb_flv);
EXPECT_EQ(0xd3, (uint8_t)flv[0]); EXPECT_EQ(0xd3, (uint8_t)flv[0]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
// For Speex frame. // For Speex frame.
@ -523,7 +523,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
EXPECT_EQ(6, nb_flv); EXPECT_EQ(6, nb_flv);
EXPECT_EQ(0xb3, (uint8_t)flv[0]); EXPECT_EQ(0xb3, (uint8_t)flv[0]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+1,5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
// For AAC frame. // For AAC frame.
@ -539,7 +539,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
EXPECT_EQ(0xa3, (uint8_t)flv[0]); EXPECT_EQ(0xa3, (uint8_t)flv[0]);
EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_EQ(0x04, (uint8_t)flv[1]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
if (true) { if (true) {
SrsRawAacStream h; SrsRawAacStream h;
@ -553,7 +553,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
EXPECT_EQ(0xa6, (uint8_t)flv[0]); EXPECT_EQ(0xa6, (uint8_t)flv[0]);
EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_EQ(0x04, (uint8_t)flv[1]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
if (true) { if (true) {
SrsRawAacStream h; SrsRawAacStream h;
@ -567,7 +567,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
EXPECT_EQ(0xa5, (uint8_t)flv[0]); EXPECT_EQ(0xa5, (uint8_t)flv[0]);
EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_EQ(0x04, (uint8_t)flv[1]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
if (true) { if (true) {
SrsRawAacStream h; SrsRawAacStream h;
@ -581,7 +581,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
EXPECT_EQ(0xa7, (uint8_t)flv[0]); EXPECT_EQ(0xa7, (uint8_t)flv[0]);
EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_EQ(0x04, (uint8_t)flv[1]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
if (true) { if (true) {
SrsRawAacStream h; SrsRawAacStream h;
@ -595,7 +595,7 @@ VOID TEST(SrsAVCTest, AACMuxToFLV)
EXPECT_EQ(0xaf, (uint8_t)flv[0]); EXPECT_EQ(0xaf, (uint8_t)flv[0]);
EXPECT_EQ(0x04, (uint8_t)flv[1]); EXPECT_EQ(0x04, (uint8_t)flv[1]);
EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str()); EXPECT_STREQ("Hello", HELPER_ARR2STR(flv+2,5).c_str());
srs_freep(flv); srs_freepa(flv);
} }
} }

@ -2081,6 +2081,7 @@ VOID TEST(ProtocolHTTPTest, QueryEscape)
} else { } else {
HELPER_ASSERT_FAILED(SrsHttpUri::query_unescape(d.in, value)); HELPER_ASSERT_FAILED(SrsHttpUri::query_unescape(d.in, value));
} }
srs_freep(d.err);
} }
} }

@ -227,8 +227,11 @@ MockSrsFileReader::MockSrsFileReader(const char* src, int nb_src)
seekable = true; seekable = true;
uf = new MockSrsFile(); uf = new MockSrsFile();
uf->write((void*)src, nb_src, NULL); srs_error_t err = uf->write((void*)src, nb_src, NULL);
uf->lseek(0, SEEK_SET, NULL); srs_freep(err);
err = uf->lseek(0, SEEK_SET, NULL);
srs_freep(err);
} }
MockSrsFileReader::~MockSrsFileReader() MockSrsFileReader::~MockSrsFileReader()
@ -255,20 +258,25 @@ bool MockSrsFileReader::is_open()
int64_t MockSrsFileReader::tellg() int64_t MockSrsFileReader::tellg()
{ {
off_t offset = 0; off_t offset = 0;
lseek(0, SEEK_CUR, &offset); srs_error_t err = lseek(0, SEEK_CUR, &offset);
srs_freep(err);
return offset; return offset;
} }
void MockSrsFileReader::skip(int64_t _size) void MockSrsFileReader::skip(int64_t _size)
{ {
int64_t offset = tellg() + _size; int64_t offset = tellg() + _size;
lseek(offset, SEEK_SET, NULL); srs_error_t err = lseek(offset, SEEK_SET, NULL);
srs_freep(err);
} }
int64_t MockSrsFileReader::seek2(int64_t _offset) int64_t MockSrsFileReader::seek2(int64_t _offset)
{ {
off_t offset = 0; off_t offset = 0;
lseek(_offset, SEEK_SET, &offset); srs_error_t err = lseek(_offset, SEEK_SET, &offset);
srs_freep(err);
return offset; return offset;
} }
@ -277,7 +285,8 @@ int64_t MockSrsFileReader::filesize()
int64_t cur = tellg(); int64_t cur = tellg();
off_t offset = 0; off_t offset = 0;
lseek(0, SEEK_END, &offset); srs_error_t err = lseek(0, SEEK_END, &offset);
srs_freep(err);
seek2(cur); seek2(cur);
return offset; return offset;
@ -298,7 +307,8 @@ srs_error_t MockSrsFileReader::lseek(off_t offset, int whence, off_t* seeked)
void MockSrsFileReader::mock_append_data(const char* data, int size) void MockSrsFileReader::mock_append_data(const char* data, int size)
{ {
uf->write((void*)data, size, NULL); srs_error_t err = uf->write((void*)data, size, NULL);
srs_freep(err);
} }
void MockSrsFileReader::mock_reset_offset() void MockSrsFileReader::mock_reset_offset()
@ -1127,6 +1137,11 @@ VOID TEST(KernelFLVTest, CoverVodStreamErrorCase)
HELPER_EXPECT_FAILED(d.seek2(1)); HELPER_EXPECT_FAILED(d.seek2(1));
} }
}
VOID TEST(KernelFLVTest, CoverVodStreamErrorCase2)
{
srs_error_t err;
if (true) { if (true) {
MockSrsFileReader r("HELLO", 5); MockSrsFileReader r("HELLO", 5);
@ -3076,22 +3091,21 @@ VOID TEST(KernelUtility, RTMPUtils2)
VOID TEST(KernelErrorTest, CoverAll) VOID TEST(KernelErrorTest, CoverAll)
{ {
srs_error_t err;
if (true) { if (true) {
EXPECT_TRUE(srs_is_system_control_error(srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "err"))); EXPECT_TRUE(srs_is_system_control_error(err = srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "err"))); srs_freep(err);
EXPECT_TRUE(srs_is_system_control_error(srs_error_new(ERROR_CONTROL_REPUBLISH, "err"))); EXPECT_TRUE(srs_is_system_control_error(err = srs_error_new(ERROR_CONTROL_REPUBLISH, "err"))); srs_freep(err);
EXPECT_TRUE(srs_is_system_control_error(srs_error_new(ERROR_CONTROL_REDIRECT, "err"))); EXPECT_TRUE(srs_is_system_control_error(err = srs_error_new(ERROR_CONTROL_REDIRECT, "err"))); srs_freep(err);
} }
if (true) { if (true) {
srs_error_t err = srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "control error"); EXPECT_TRUE(srs_is_system_control_error(err = srs_error_new(ERROR_CONTROL_RTMP_CLOSE, "control error"))); srs_freep(err);
EXPECT_TRUE(srs_is_system_control_error(err));
srs_freep(err);
} }
if (true) { if (true) {
EXPECT_TRUE(srs_is_client_gracefully_close(srs_error_new(ERROR_SOCKET_READ, "err"))); EXPECT_TRUE(srs_is_client_gracefully_close(err = srs_error_new(ERROR_SOCKET_READ, "err"))); srs_freep(err);
EXPECT_TRUE(srs_is_client_gracefully_close(srs_error_new(ERROR_SOCKET_READ_FULLY, "err"))); EXPECT_TRUE(srs_is_client_gracefully_close(err = srs_error_new(ERROR_SOCKET_READ_FULLY, "err"))); srs_freep(err);
EXPECT_TRUE(srs_is_client_gracefully_close(srs_error_new(ERROR_SOCKET_WRITE, "err"))); EXPECT_TRUE(srs_is_client_gracefully_close(err = srs_error_new(ERROR_SOCKET_WRITE, "err"))); srs_freep(err);
} }
if (true) { if (true) {
@ -5646,8 +5660,11 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c 0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c
}; };
HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw)));
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
SrsAutoFreeA(uint8_t, cp);
HELPER_EXPECT_SUCCESS(enc.write_sample( HELPER_EXPECT_SUCCESS(enc.write_sample(
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 0, 0, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 0, 0, cp, fmt.nb_raw
)); ));
} }
@ -5656,8 +5673,11 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
0xaf, 0x00, 0x12, 0x10 0xaf, 0x00, 0x12, 0x10
}; };
HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw)));
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
SrsAutoFreeA(uint8_t, cp);
HELPER_EXPECT_SUCCESS(enc.write_sample( HELPER_EXPECT_SUCCESS(enc.write_sample(
SrsMp4HandlerTypeSOUN, 0x00, 0, 0, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw SrsMp4HandlerTypeSOUN, 0x00, 0, 0, cp, fmt.nb_raw
)); ));
} }
@ -5672,8 +5692,11 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e
}; };
HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw))); HELPER_EXPECT_SUCCESS(fmt.on_audio(0, (char*)raw, sizeof(raw)));
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
SrsAutoFreeA(uint8_t, cp);
HELPER_EXPECT_SUCCESS(enc.write_sample( HELPER_EXPECT_SUCCESS(enc.write_sample(
SrsMp4HandlerTypeSOUN, 0x00, 34, 34, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw SrsMp4HandlerTypeSOUN, 0x00, 34, 34, cp, fmt.nb_raw
)); ));
} }
@ -5691,8 +5714,11 @@ VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
0xb2, 0x72, 0x5a 0xb2, 0x72, 0x5a
}; };
HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw))); HELPER_EXPECT_SUCCESS(fmt.on_video(0, (char*)raw, sizeof(raw)));
uint8_t* cp = mock_copy_bytes(fmt.raw, fmt.nb_raw);
SrsAutoFreeA(uint8_t, cp);
HELPER_EXPECT_SUCCESS(enc.write_sample( HELPER_EXPECT_SUCCESS(enc.write_sample(
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 40, 40, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 40, 40, cp, fmt.nb_raw
)); ));
} }

@ -85,6 +85,8 @@ MockBufferIO::MockBufferIO()
MockBufferIO::~MockBufferIO() MockBufferIO::~MockBufferIO()
{ {
srs_freep(in_err);
srs_freep(out_err);
} }
int MockBufferIO::length() int MockBufferIO::length()
@ -397,7 +399,7 @@ VOID TEST(ProtocolHandshakeTest, VerifyFPC0C1)
// manually validate the c1 // manually validate the c1
// @see: calc_c1_digest // @see: calc_c1_digest
char* c1s1_joined_bytes = new char[1536 -32]; char* c1s1_joined_bytes = new char[1536 -32];
SrsAutoFree(char, c1s1_joined_bytes); SrsAutoFreeA(char, c1s1_joined_bytes);
HELPER_ASSERT_SUCCESS( c1.payload->copy_to(&c1, c1s1_joined_bytes, 1536 - 32, false)); HELPER_ASSERT_SUCCESS( c1.payload->copy_to(&c1, c1s1_joined_bytes, 1536 - 32, false));
bool is_valid; bool is_valid;
@ -599,6 +601,13 @@ VOID TEST(ProtocolUtilityTest, GenerateTcUrl)
EXPECT_STREQ("rtmp://demo:19351/live", tcUrl.c_str()); EXPECT_STREQ("rtmp://demo:19351/live", tcUrl.c_str());
} }
void srs_utest_free_message_array(SrsMessageArray* arr)
{
for (int i = 0; i < arr->max; i++) {
srs_freep(arr->msgs[i]);
}
}
/** /**
* shared ptr message array test * shared ptr message array test
*/ */
@ -614,6 +623,9 @@ VOID TEST(ProtocolMsgArrayTest, MessageArray)
if (true) { if (true) {
SrsMessageArray arr(3); SrsMessageArray arr(3);
SrsMessageArray* parr = &arr;
SrsAutoFreeH(SrsMessageArray, parr, srs_utest_free_message_array);
arr.msgs[0] = msg.copy(); arr.msgs[0] = msg.copy();
EXPECT_EQ(1, msg.count()); EXPECT_EQ(1, msg.count());
@ -624,18 +636,21 @@ VOID TEST(ProtocolMsgArrayTest, MessageArray)
arr.msgs[2] = msg.copy(); arr.msgs[2] = msg.copy();
EXPECT_EQ(3, msg.count()); EXPECT_EQ(3, msg.count());
} }
EXPECT_EQ(3, msg.count()); EXPECT_EQ(0, msg.count());
if (true) { if (true) {
SrsMessageArray arr(3); SrsMessageArray arr(3);
SrsMessageArray* parr = &arr;
SrsAutoFreeH(SrsMessageArray, parr, srs_utest_free_message_array);
arr.msgs[0] = msg.copy(); arr.msgs[0] = msg.copy();
EXPECT_EQ(4, msg.count()); EXPECT_EQ(1, msg.count());
arr.msgs[2] = msg.copy(); arr.msgs[2] = msg.copy();
EXPECT_EQ(5, msg.count()); EXPECT_EQ(2, msg.count());
} }
EXPECT_EQ(5, msg.count()); EXPECT_EQ(0, msg.count());
} }
/** /**
@ -2720,7 +2735,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendVMessage)
uint8_t data[] = {0x01, 0x02, 0x03, 0x04}; uint8_t data[] = {0x01, 0x02, 0x03, 0x04};
SrsCommonMessage* msg = new SrsCommonMessage(); SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg);
msg->size = sizeof(data); msg->size = sizeof(data);
msg->payload = new char[msg->size]; msg->payload = new char[msg->size];
memcpy(msg->payload, data, msg->size); memcpy(msg->payload, data, msg->size);
@ -2831,7 +2846,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsCreateStreamPacket)
SrsProtocol proto(&bio); SrsProtocol proto(&bio);
SrsCreateStreamPacket* pkt = new SrsCreateStreamPacket(); SrsCreateStreamPacket* pkt = new SrsCreateStreamPacket();
pkt->command_object = SrsAmf0Any::null(); pkt->set_command_object(SrsAmf0Any::null());
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -2856,7 +2871,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartPacket)
SrsFMLEStartPacket* pkt = new SrsFMLEStartPacket(); SrsFMLEStartPacket* pkt = new SrsFMLEStartPacket();
pkt->command_name = "FMLEStart"; pkt->command_name = "FMLEStart";
pkt->command_object = SrsAmf0Any::null(); pkt->set_command_object(SrsAmf0Any::null());
pkt->stream_name = "livestream"; pkt->stream_name = "livestream";
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
@ -2885,8 +2900,8 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartResPacket)
SrsFMLEStartResPacket* pkt = new SrsFMLEStartResPacket(1); SrsFMLEStartResPacket* pkt = new SrsFMLEStartResPacket(1);
pkt->command_name = "FMLEStart"; pkt->command_name = "FMLEStart";
pkt->command_object = SrsAmf0Any::null(); pkt->set_command_object(SrsAmf0Any::null());
pkt->args = args; pkt->set_args(args);
args->set("stream" , SrsAmf0Any::str("livestream")); args->set("stream" , SrsAmf0Any::str("livestream"));
args->set("start" , SrsAmf0Any::number(0)); args->set("start" , SrsAmf0Any::number(0));
@ -2914,7 +2929,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsPublishPacket)
SrsPublishPacket* pkt = new SrsPublishPacket(); SrsPublishPacket* pkt = new SrsPublishPacket();
pkt->command_name = "publish"; pkt->command_name = "publish";
pkt->command_object = SrsAmf0Any::null(); pkt->set_command_object(SrsAmf0Any::null());
pkt->stream_name = "livestream"; pkt->stream_name = "livestream";
pkt->type = "live"; pkt->type = "live";
@ -2945,8 +2960,8 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsPlayResPacket)
SrsPlayResPacket* pkt = new SrsPlayResPacket(); SrsPlayResPacket* pkt = new SrsPlayResPacket();
pkt->command_name = "_result"; pkt->command_name = "_result";
pkt->command_object = SrsAmf0Any::null(); pkt->set_command_object(SrsAmf0Any::null());
pkt->desc = args; pkt->set_desc(args);
args->set("stream" , SrsAmf0Any::str("livestream")); args->set("stream" , SrsAmf0Any::str("livestream"));
args->set("start" , SrsAmf0Any::number(0)); args->set("start" , SrsAmf0Any::number(0));
@ -2979,7 +2994,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnBWDonePacket)
SrsOnBWDonePacket* pkt = new SrsOnBWDonePacket(); SrsOnBWDonePacket* pkt = new SrsOnBWDonePacket();
pkt->command_name = "onBWDone"; pkt->command_name = "onBWDone";
pkt->args = SrsAmf0Any::null(); pkt->set_args(SrsAmf0Any::null());
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -3009,8 +3024,8 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusCallPacket)
SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket(); SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();
pkt->command_name = "onStatus"; pkt->command_name = "onStatus";
pkt->args = SrsAmf0Any::null(); pkt->set_args(SrsAmf0Any::null());
pkt->data = args; pkt->set_data(args);
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -3045,7 +3060,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusDataPacket)
SrsOnStatusDataPacket* pkt = new SrsOnStatusDataPacket(); SrsOnStatusDataPacket* pkt = new SrsOnStatusDataPacket();
pkt->command_name = "onData"; pkt->command_name = "onData";
pkt->data = args; pkt->set_data(args);
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
char buf[] = { char buf[] = {
@ -3104,7 +3119,7 @@ VOID TEST(ProtocolStackTest, ProtocolSendSrsOnMetaDataPacket)
SrsOnMetaDataPacket* pkt = new SrsOnMetaDataPacket(); SrsOnMetaDataPacket* pkt = new SrsOnMetaDataPacket();
pkt->name = "onMetaData"; pkt->name = "onMetaData";
pkt->metadata = args; pkt->set_metadata(args);
HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0)); HELPER_EXPECT_SUCCESS(proto.send_and_free_packet(pkt, 0));
uint8_t buf[] = { uint8_t buf[] = {
@ -3299,7 +3314,7 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow)
} }
if (true) { if (true) {
SrsCommonMessage* msg = new SrsCommonMessage(); SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg);
msg->header.payload_length = msg->size = 4096; msg->header.payload_length = msg->size = 4096;
msg->payload = new char[msg->size]; msg->payload = new char[msg->size];
@ -3340,15 +3355,14 @@ VOID TEST(ProtocolStackTest, ProtocolAckSizeFlow)
} }
// recv auto send acked size. #1 // recv auto send acked size. #1
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg)); HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
SrsAutoFree(SrsCommonMessage, msg);
ASSERT_TRUE(msg->header.is_ackledgement()); ASSERT_TRUE(msg->header.is_ackledgement());
} }
// send again // send again
if (true) { if (true) {
SrsCommonMessage* msg = new SrsCommonMessage(); SrsCommonMessage* msg = new SrsCommonMessage(); SrsAutoFree(SrsCommonMessage, msg);
msg->header.payload_length = msg->size = 4096; msg->header.payload_length = msg->size = 4096;
msg->payload = new char[msg->size]; msg->payload = new char[msg->size];
@ -3425,12 +3439,11 @@ VOID TEST(ProtocolStackTest, ProtocolPingFlow)
} }
// recv ping // recv ping
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_ASSERT_SUCCESS(proto.recv_message(&msg)); HELPER_ASSERT_SUCCESS(proto.recv_message(&msg));
SrsAutoFree(SrsCommonMessage, msg);
ASSERT_TRUE(msg->header.is_user_control_message()); ASSERT_TRUE(msg->header.is_user_control_message());
SrsPacket* pkt = NULL; SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt);
HELPER_ASSERT_SUCCESS(proto.decode_message(msg, &pkt)); HELPER_ASSERT_SUCCESS(proto.decode_message(msg, &pkt));
SrsUserControlPacket* spkt = dynamic_cast<SrsUserControlPacket*>(pkt); SrsUserControlPacket* spkt = dynamic_cast<SrsUserControlPacket*>(pkt);
ASSERT_TRUE(spkt != NULL); ASSERT_TRUE(spkt != NULL);

@ -68,7 +68,7 @@ VOID TEST(KernelRTCTest, RtpSTAPPayloadException)
EXPECT_TRUE(nalu_type == kStapA); EXPECT_TRUE(nalu_type == kStapA);
ISrsRtpPayloader* payload = new SrsRtpSTAPPayload(); ISrsRtpPayloader* payload = new SrsRtpSTAPPayload();
EXPECT_TRUE((err = payload->decode(&buf)) != srs_success); HELPER_ASSERT_FAILED(payload->decode(&buf));
srs_freep(payload); srs_freep(payload);
} }
@ -710,7 +710,8 @@ VOID TEST(KernelRTCTest, NACKFetchRTPPacket)
SrsRtcPlayStream play(&s, SrsContextId()); SrsRtcPlayStream play(&s, SrsContextId());
SrsRtcTrackDescription ds; SrsRtcTrackDescription ds;
SrsRtcVideoSendTrack *track = new SrsRtcVideoSendTrack(&s, &ds); SrsRtcVideoSendTrack* track = new SrsRtcVideoSendTrack(&s, &ds);
SrsAutoFree(SrsRtcVideoSendTrack, track);
// The RTP queue will free the packet. // The RTP queue will free the packet.
if (true) { if (true) {

@ -435,10 +435,9 @@ VOID TEST(ProtocolRTMPTest, OnDecodeMessages)
// Always response ACK message. // Always response ACK message.
HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1)); HELPER_EXPECT_SUCCESS(p.set_in_window_ack_size(1));
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
io.in_buffer.append(&bytes); io.in_buffer.append(&bytes);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
srs_freep(msg);
} }
} }
@ -884,8 +883,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage)
uint8_t bytes[] = {0x01, 0x00, 0x00}; uint8_t bytes[] = {0x01, 0x00, 0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes)); io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
} }
@ -896,8 +894,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage)
uint8_t bytes[] = {0x00, 0x00}; uint8_t bytes[] = {0x00, 0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes)); io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
} }
@ -908,8 +905,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage)
uint8_t bytes[] = {0x00}; uint8_t bytes[] = {0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes)); io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
} }
@ -917,8 +913,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage)
MockBufferIO io; MockBufferIO io;
SrsProtocol p(&io); SrsProtocol p(&io);
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
} }
} }
@ -934,8 +929,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3}; uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes, sizeof(bytes)); io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
} }
@ -948,10 +942,12 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3}; uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes, sizeof(bytes)); io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg; if (true) {
SrsAutoFree(SrsCommonMessage, msg); SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
uint8_t bytes2[] = {0x43, 0,0,0, 0,0,5, 0, 0,0,0,0, 1,2,3}; uint8_t bytes2[] = {0x43, 0,0,0, 0,0,5, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes2, sizeof(bytes2)); io.in_buffer.append((char*)bytes2, sizeof(bytes2));
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
@ -964,8 +960,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
uint8_t bytes[] = {0x03}; uint8_t bytes[] = {0x03};
io.in_buffer.append((char*)bytes, sizeof(bytes)); io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
} }
@ -976,8 +971,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage2)
uint8_t bytes[] = {0x43, 0,0,0, 0,0,0, 0}; uint8_t bytes[] = {0x43, 0,0,0, 0,0,0, 0};
io.in_buffer.append((char*)bytes, sizeof(bytes)); io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg)); HELPER_EXPECT_FAILED(p.recv_message(&msg));
} }
} }
@ -1060,8 +1054,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4)
io.in_buffer.append(&io.out_buffer); io.in_buffer.append(&io.out_buffer);
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
EXPECT_EQ(256, p.out_chunk_size); EXPECT_EQ(256, p.out_chunk_size);
@ -1078,8 +1071,7 @@ VOID TEST(ProtocolRTMPTest, RecvMessage4)
io.in_buffer.append(&io.out_buffer); io.in_buffer.append(&io.out_buffer);
SrsCommonMessage* msg; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
EXPECT_EQ(256, p.in_buffer_length); EXPECT_EQ(256, p.in_buffer_length);
@ -1534,9 +1526,8 @@ VOID TEST(ProtocolRTMPTest, ServerCommandMessage)
SrsProtocol p(&tio); SrsProtocol p(&tio);
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
srs_freep(msg);
EXPECT_EQ(1024, p.in_chunk_size); EXPECT_EQ(1024, p.in_chunk_size);
} }
@ -2239,7 +2230,7 @@ VOID TEST(ProtocolRTMPTest, CoverAll)
EXPECT_EQ(0, r.get_recv_bytes()); EXPECT_EQ(0, r.get_recv_bytes());
EXPECT_EQ(0, r.get_send_bytes()); EXPECT_EQ(0, r.get_send_bytes());
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(r.recv_message(&msg)); HELPER_EXPECT_FAILED(r.recv_message(&msg));
SrsCallPacket* pkt = new SrsCallPacket(); SrsCallPacket* pkt = new SrsCallPacket();
@ -2262,7 +2253,7 @@ VOID TEST(ProtocolRTMPTest, CoverAll)
EXPECT_EQ(0, r.get_recv_bytes()); EXPECT_EQ(0, r.get_recv_bytes());
EXPECT_EQ(0, r.get_send_bytes()); EXPECT_EQ(0, r.get_send_bytes());
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(r.recv_message(&msg)); HELPER_EXPECT_FAILED(r.recv_message(&msg));
SrsCallPacket* pkt = new SrsCallPacket(); SrsCallPacket* pkt = new SrsCallPacket();
@ -2585,8 +2576,8 @@ VOID TEST(ProtocolRTMPTest, ConnectAppWithArgs)
if (true) { if (true) {
tio.in_buffer.append(&io.out_buffer); tio.in_buffer.append(&io.out_buffer);
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
SrsConnectAppPacket* pkt = NULL; SrsConnectAppPacket* pkt = NULL; SrsAutoFree(SrsConnectAppPacket, pkt);
HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt)); HELPER_ASSERT_SUCCESS(p.expect_message(&msg, &pkt));
SrsAmf0Any* prop = pkt->command_object->get_property("tcUrl"); SrsAmf0Any* prop = pkt->command_object->get_property("tcUrl");
@ -2616,9 +2607,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
srs_freep(msg);
} }
} }
@ -2633,14 +2623,11 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_ASSERT_SUCCESS(p.recv_message(&msg)); HELPER_ASSERT_SUCCESS(p.recv_message(&msg));
SrsPacket* pkt = NULL; SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt);
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt)); HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
srs_freep(msg);
srs_freep(pkt);
} }
} }
@ -2655,9 +2642,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
srs_freep(msg);
} }
} }
@ -2672,14 +2658,11 @@ VOID TEST(ProtocolRTMPTest, AgentMessageCodec)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_ASSERT_SUCCESS(p.recv_message(&msg)); HELPER_ASSERT_SUCCESS(p.recv_message(&msg));
SrsPacket* pkt = NULL; SrsPacket* pkt = NULL; SrsAutoFree(SrsPacket, pkt);
HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt)); HELPER_EXPECT_SUCCESS(p.decode_message(msg, &pkt));
srs_freep(msg);
srs_freep(pkt);
} }
} }
} }
@ -2733,17 +2716,15 @@ VOID TEST(ProtocolRTMPTest, CheckStreamID)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
EXPECT_EQ(1, msg->header.stream_id); EXPECT_EQ(1, msg->header.stream_id);
srs_freep(msg);
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
EXPECT_EQ(2, msg->header.stream_id); EXPECT_EQ(2, msg->header.stream_id);
srs_freep(msg);
} }
} }
} }
@ -2767,9 +2748,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
srs_freep(msg);
} }
} }
@ -2788,9 +2768,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
srs_freep(msg);
} }
} }
@ -2809,9 +2788,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
srs_freep(msg);
} }
} }
@ -2830,9 +2808,8 @@ VOID TEST(ProtocolRTMPTest, AgentMessageTransform)
} }
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(p.recv_message(&msg)); HELPER_EXPECT_SUCCESS(p.recv_message(&msg));
srs_freep(msg);
} }
} }
} }
@ -2865,9 +2842,8 @@ VOID TEST(ProtocolRTMPTest, MergeReadHandler)
r.set_merge_read(true, &h); r.set_merge_read(true, &h);
if (true) { if (true) {
SrsCommonMessage* msg = NULL; SrsCommonMessage* msg = NULL; SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_SUCCESS(r.recv_message(&msg)); HELPER_EXPECT_SUCCESS(r.recv_message(&msg));
srs_freep(msg);
} }
EXPECT_TRUE(h.nn > 0); EXPECT_TRUE(h.nn > 0);
@ -2925,6 +2901,8 @@ VOID TEST(ProtocolRTMPTest, CreateRTMPMessage)
} }
} }
extern void srs_utest_free_message_array(SrsMessageArray* arr);
VOID TEST(ProtocolRTMPTest, OthersAll) VOID TEST(ProtocolRTMPTest, OthersAll)
{ {
if (true) { if (true) {
@ -2995,6 +2973,10 @@ VOID TEST(ProtocolRTMPTest, OthersAll)
if (true) { if (true) {
SrsMessageArray h(10); SrsMessageArray h(10);
SrsMessageArray* parr = &h;
SrsAutoFreeH(SrsMessageArray, parr, srs_utest_free_message_array);
h.msgs[0] = new SrsSharedPtrMessage(); h.msgs[0] = new SrsSharedPtrMessage();
h.msgs[1] = new SrsSharedPtrMessage(); h.msgs[1] = new SrsSharedPtrMessage();
EXPECT_TRUE(NULL != h.msgs[0]); EXPECT_TRUE(NULL != h.msgs[0]);

@ -636,6 +636,7 @@ VOID TEST(HTTPServerTest, ContentLength)
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
SrsAutoFree(ISrsHttpMessage, msg);
char buf[32]; ssize_t nread = 0; char buf[32]; ssize_t nread = 0;
ISrsHttpResponseReader* r = msg->body_reader(); ISrsHttpResponseReader* r = msg->body_reader();
@ -664,6 +665,7 @@ VOID TEST(HTTPServerTest, HTTPChunked)
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
SrsAutoFree(ISrsHttpMessage, msg);
char buf[32]; ssize_t nread = 0; char buf[32]; ssize_t nread = 0;
ISrsHttpResponseReader* r = msg->body_reader(); ISrsHttpResponseReader* r = msg->body_reader();
@ -720,6 +722,7 @@ VOID TEST(HTTPServerTest, InfiniteChunked)
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
SrsAutoFree(ISrsHttpMessage, msg);
char buf[32]; ssize_t nread = 0; char buf[32]; ssize_t nread = 0;
ISrsHttpResponseReader* r = msg->body_reader(); ISrsHttpResponseReader* r = msg->body_reader();
@ -1110,7 +1113,7 @@ VOID TEST(TCPServerTest, CoverUtility)
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
addrinfo* r = NULL; addrinfo* r = NULL;
SrsAutoFree(addrinfo, r); SrsAutoFreeH(addrinfo, r, freeaddrinfo);
ASSERT_TRUE(!getaddrinfo("127.0.0.1", NULL, &hints, &r)); ASSERT_TRUE(!getaddrinfo("127.0.0.1", NULL, &hints, &r));
EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr));
@ -1123,7 +1126,7 @@ VOID TEST(TCPServerTest, CoverUtility)
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
addrinfo* r = NULL; addrinfo* r = NULL;
SrsAutoFree(addrinfo, r); SrsAutoFreeH(addrinfo, r, freeaddrinfo);
ASSERT_TRUE(!getaddrinfo("192.168.0.1", NULL, &hints, &r)); ASSERT_TRUE(!getaddrinfo("192.168.0.1", NULL, &hints, &r));
EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr));
@ -1168,7 +1171,7 @@ VOID TEST(TCPServerTest, CoverUtility)
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
addrinfo* r = NULL; addrinfo* r = NULL;
SrsAutoFree(addrinfo, r); SrsAutoFreeH(addrinfo, r, freeaddrinfo);
ASSERT_TRUE(!getaddrinfo("2001:da8:6000:291:21f:d0ff:fed4:928c", NULL, &hints, &r)); ASSERT_TRUE(!getaddrinfo("2001:da8:6000:291:21f:d0ff:fed4:928c", NULL, &hints, &r));
EXPECT_TRUE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); EXPECT_TRUE(srs_net_device_is_internet((sockaddr*)r->ai_addr));
@ -1179,7 +1182,7 @@ VOID TEST(TCPServerTest, CoverUtility)
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
addrinfo* r = NULL; addrinfo* r = NULL;
SrsAutoFree(addrinfo, r); SrsAutoFreeH(addrinfo, r, freeaddrinfo);
ASSERT_TRUE(!getaddrinfo("3ffe:dead:beef::1", NULL, &hints, &r)); ASSERT_TRUE(!getaddrinfo("3ffe:dead:beef::1", NULL, &hints, &r));
EXPECT_TRUE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); EXPECT_TRUE(srs_net_device_is_internet((sockaddr*)r->ai_addr));
@ -1192,7 +1195,7 @@ VOID TEST(TCPServerTest, CoverUtility)
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
addrinfo* r = NULL; addrinfo* r = NULL;
SrsAutoFree(addrinfo, r); SrsAutoFreeH(addrinfo, r, freeaddrinfo);
ASSERT_TRUE(!getaddrinfo("::", NULL, &hints, &r)); ASSERT_TRUE(!getaddrinfo("::", NULL, &hints, &r));
EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr));
@ -1205,7 +1208,7 @@ VOID TEST(TCPServerTest, CoverUtility)
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
addrinfo* r = NULL; addrinfo* r = NULL;
SrsAutoFree(addrinfo, r); SrsAutoFreeH(addrinfo, r, freeaddrinfo);
ASSERT_TRUE(!getaddrinfo("fec0::", NULL, &hints, &r)); ASSERT_TRUE(!getaddrinfo("fec0::", NULL, &hints, &r));
EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr));
@ -1218,7 +1221,7 @@ VOID TEST(TCPServerTest, CoverUtility)
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
addrinfo* r = NULL; addrinfo* r = NULL;
SrsAutoFree(addrinfo, r); SrsAutoFreeH(addrinfo, r, freeaddrinfo);
ASSERT_TRUE(!getaddrinfo("FE80::", NULL, &hints, &r)); ASSERT_TRUE(!getaddrinfo("FE80::", NULL, &hints, &r));
EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr));
@ -1231,7 +1234,7 @@ VOID TEST(TCPServerTest, CoverUtility)
hints.ai_family = AF_INET6; hints.ai_family = AF_INET6;
addrinfo* r = NULL; addrinfo* r = NULL;
SrsAutoFree(addrinfo, r); SrsAutoFreeH(addrinfo, r, freeaddrinfo);
ASSERT_TRUE(!getaddrinfo("::1", NULL, &hints, &r)); ASSERT_TRUE(!getaddrinfo("::1", NULL, &hints, &r));
EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr)); EXPECT_FALSE(srs_net_device_is_internet((sockaddr*)r->ai_addr));

@ -11,6 +11,7 @@
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_rtmp_stack.hpp>
#include <srs_app_srt_utility.hpp> #include <srs_app_srt_utility.hpp>
#include <srs_app_srt_server.hpp> #include <srs_app_srt_server.hpp>
#include <srs_core_autofree.hpp>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
@ -194,6 +195,7 @@ VOID TEST(ServiceStSRTTest, ListenConnectAccept)
HELPER_EXPECT_SUCCESS(srs_srt_socket(&srt_client_fd)); HELPER_EXPECT_SUCCESS(srs_srt_socket(&srt_client_fd));
SrsSrtSocket* srt_client_socket = new SrsSrtSocket(_srt_eventloop->poller(), srt_client_fd); SrsSrtSocket* srt_client_socket = new SrsSrtSocket(_srt_eventloop->poller(), srt_client_fd);
SrsAutoFree(SrsSrtSocket, srt_client_socket);
// No client connected, accept will timeout. // No client connected, accept will timeout.
srs_srt_t srt_fd = srs_srt_socket_invalid(); srs_srt_t srt_fd = srs_srt_socket_invalid();
@ -202,6 +204,7 @@ VOID TEST(ServiceStSRTTest, ListenConnectAccept)
err = srt_server.accept(&srt_fd); err = srt_server.accept(&srt_fd);
EXPECT_EQ(srs_error_code(err), ERROR_SRT_TIMEOUT); EXPECT_EQ(srs_error_code(err), ERROR_SRT_TIMEOUT);
EXPECT_EQ(srt_fd, srs_srt_socket_invalid()); EXPECT_EQ(srt_fd, srs_srt_socket_invalid());
srs_freep(err);
// Client connect to server // Client connect to server
HELPER_EXPECT_SUCCESS(srt_client_socket->connect(server_ip, server_port)); HELPER_EXPECT_SUCCESS(srt_client_socket->connect(server_ip, server_port));
@ -308,6 +311,7 @@ VOID TEST(ServiceStSRTTest, ReadWrite)
// Recv msg from client, but client no send any msg, so will be timeout. // Recv msg from client, but client no send any msg, so will be timeout.
err = srt_server_accepted_socket->recvmsg(buf, sizeof(buf), &nb_read); err = srt_server_accepted_socket->recvmsg(buf, sizeof(buf), &nb_read);
EXPECT_EQ(srs_error_code(err), ERROR_SRT_TIMEOUT); EXPECT_EQ(srs_error_code(err), ERROR_SRT_TIMEOUT);
srs_freep(err);
} }
} }
@ -524,7 +528,7 @@ VOID TEST(ServiceSRTTest, Encrypt)
if (true) { if (true) {
int pbkeylens[4] = {0, 16, 24, 32}; int pbkeylens[4] = {0, 16, 24, 32};
for (int i = 0; i < sizeof(pbkeylens) / sizeof(pbkeylens[0]); ++i) { for (int i = 0; i < (int)(sizeof(pbkeylens) / sizeof(pbkeylens[0])); ++i) {
srs_srt_t srt_client_fd = srs_srt_socket_invalid(); srs_srt_t srt_client_fd = srs_srt_socket_invalid();
HELPER_EXPECT_SUCCESS(srs_srt_socket_with_default_option(&srt_client_fd)); HELPER_EXPECT_SUCCESS(srs_srt_socket_with_default_option(&srt_client_fd));
HELPER_EXPECT_SUCCESS(srs_srt_set_streamid(srt_client_fd, streamid)); HELPER_EXPECT_SUCCESS(srs_srt_set_streamid(srt_client_fd, streamid));

Loading…
Cancel
Save