Skip to content

Commit

Permalink
merge srs2, use srs_freepa for array
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 2, 2015
1 parent cef1ae5 commit 8cec06e
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 65 deletions.
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_caster_flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ int SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec)

char* data = new char[size];
if ((ret = dec->read_tag_data(data, size)) != ERROR_SUCCESS) {
srs_freep(data);
srs_freepa(data);
if (!srs_is_client_gracefully_close(ret)) {
srs_error("flv: proxy tag data failed. ret=%d", ret);
}
Expand Down
7 changes: 3 additions & 4 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace _srs_internal

SrsConfigBuffer::~SrsConfigBuffer()
{
srs_freep(start);
srs_freepa(start);
}

int SrsConfigBuffer::fullfill(const char* filename)
Expand All @@ -146,7 +146,7 @@ namespace _srs_internal
int filesize = (int)reader.filesize();

// create buffer
srs_freep(start);
srs_freepa(start);
pos = last = start = new char[filesize];
end = start + filesize;

Expand Down Expand Up @@ -1091,7 +1091,7 @@ int SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector<string>& args,
if (!word_str.empty()) {
args.push_back(word_str);
}
srs_freep(aword);
srs_freepa(aword);

if (ch == ';') {
return ERROR_SYSTEM_CONFIG_DIRECTIVE;
Expand Down Expand Up @@ -6833,4 +6833,3 @@ SrsConfDirective* SrsConfig::get_stats_disk_device()

return conf;
}

6 changes: 3 additions & 3 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ SrsHttpResponseWriter::SrsHttpResponseWriter(SrsStSocket* io)
SrsHttpResponseWriter::~SrsHttpResponseWriter()
{
srs_freep(hdr);
srs_freep(iovss_cache);
srs_freepa(iovss_cache);
}

int SrsHttpResponseWriter::final_request()
Expand Down Expand Up @@ -191,7 +191,7 @@ int SrsHttpResponseWriter::writev(iovec* iov, int iovcnt, ssize_t* pnwrite)
int nb_iovss = 3 + iovcnt;
iovec* iovss = iovss_cache;
if (nb_iovss_cache < nb_iovss) {
srs_freep(iovss_cache);
srs_freepa(iovss_cache);
nb_iovss_cache = nb_iovss;
iovss = iovss_cache = new iovec[nb_iovss];
}
Expand Down Expand Up @@ -509,7 +509,7 @@ SrsHttpMessage::~SrsHttpMessage()
{
srs_freep(_body);
srs_freep(_uri);
srs_freep(_http_ts_send_buffer);
srs_freepa(_http_ts_send_buffer);
}

int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, SrsFastStream* body, vector<SrsHttpHeaderField>& headers)
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ SrsUdpListener::~SrsUdpListener()
// close it manually.
close(_fd);

srs_freep(buf);
srs_freepa(buf);
}

int SrsUdpListener::fd()
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ SrsFastLog::SrsFastLog()

SrsFastLog::~SrsFastLog()
{
srs_freep(log_data);
srs_freepa(log_data);

if (fd > 0) {
::close(fd);
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ SrsFastVector::SrsFastVector()
SrsFastVector::~SrsFastVector()
{
free();
srs_freep(msgs);
srs_freepa(msgs);
}

int SrsFastVector::size()
Expand Down Expand Up @@ -221,7 +221,7 @@ void SrsFastVector::push_back(SrsSharedPtrMessage* msg)
srs_warn("fast vector incrase %d=>%d", nb_msgs, size);

// use new array.
srs_freep(msgs);
srs_freepa(msgs);
msgs = buf;
nb_msgs = size;
}
Expand Down
11 changes: 8 additions & 3 deletions trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
p = NULL; \
} \
(void)0
// sometimes, the freepa is useless,
// it's recomments to free each elem explicit.
// so we remove the srs_freepa utility.
// please use the freepa(T[]) to free an array,
// or the behavior is undefined.
#define srs_freepa(pa) \
if (pa) { \
delete[] pa; \
pa = NULL; \
} \
(void)0

/**
* disable copy constructor of class,
Expand Down
16 changes: 8 additions & 8 deletions trunk/src/kernel/srs_kernel_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ SrsAvcAacCodec::SrsAvcAacCodec()

SrsAvcAacCodec::~SrsAvcAacCodec()
{
srs_freep(avc_extra_data);
srs_freep(aac_extra_data);
srs_freepa(avc_extra_data);
srs_freepa(aac_extra_data);

srs_freep(stream);
srs_freep(sequenceParameterSetNALUnit);
srs_freep(pictureParameterSetNALUnit);
srs_freepa(sequenceParameterSetNALUnit);
srs_freepa(pictureParameterSetNALUnit);
}

bool SrsAvcAacCodec::is_avc_codec_ok()
Expand Down Expand Up @@ -500,7 +500,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample
// 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33.
aac_extra_size = stream->size() - stream->pos();
if (aac_extra_size > 0) {
srs_freep(aac_extra_data);
srs_freepa(aac_extra_data);
aac_extra_data = new char[aac_extra_size];
memcpy(aac_extra_data, stream->data() + stream->pos(), aac_extra_size);

Expand Down Expand Up @@ -764,7 +764,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsBuffer* stream)
// 5.2.4.1.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16
avc_extra_size = stream->size() - stream->pos();
if (avc_extra_size > 0) {
srs_freep(avc_extra_data);
srs_freepa(avc_extra_data);
avc_extra_data = new char[avc_extra_size];
memcpy(avc_extra_data, stream->data() + stream->pos(), avc_extra_size);
}
Expand Down Expand Up @@ -825,7 +825,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsBuffer* stream)
return ret;
}
if (sequenceParameterSetLength > 0) {
srs_freep(sequenceParameterSetNALUnit);
srs_freepa(sequenceParameterSetNALUnit);
sequenceParameterSetNALUnit = new char[sequenceParameterSetLength];
stream->read_bytes(sequenceParameterSetNALUnit, sequenceParameterSetLength);
}
Expand Down Expand Up @@ -854,7 +854,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsBuffer* stream)
return ret;
}
if (pictureParameterSetLength > 0) {
srs_freep(pictureParameterSetNALUnit);
srs_freepa(pictureParameterSetNALUnit);
pictureParameterSetNALUnit = new char[pictureParameterSetLength];
stream->read_bytes(pictureParameterSetNALUnit, pictureParameterSetLength);
}
Expand Down
18 changes: 9 additions & 9 deletions trunk/src/kernel/srs_kernel_flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ SrsCommonMessage::~SrsCommonMessage()
#ifdef SRS_AUTO_MEM_WATCH
srs_memory_unwatch(payload);
#endif
srs_freep(payload);
srs_freepa(payload);
}

void SrsCommonMessage::create_payload(int size)
{
srs_freep(payload);
srs_freepa(payload);

payload = new char[size];
srs_verbose("create payload for RTMP message. size=%d", size);
Expand All @@ -190,7 +190,7 @@ SrsSharedPtrMessage::SrsSharedPtrPayload::~SrsSharedPtrPayload()
#ifdef SRS_AUTO_MEM_WATCH
srs_memory_unwatch(payload);
#endif
srs_freep(payload);
srs_freepa(payload);
}

SrsSharedPtrMessage::SrsSharedPtrMessage()
Expand Down Expand Up @@ -350,9 +350,9 @@ SrsFlvEncoder::~SrsFlvEncoder()
srs_freep(tag_stream);

#ifdef SRS_PERF_FAST_FLV_ENCODER
srs_freep(tag_headers);
srs_freep(iovss_cache);
srs_freep(ppts);
srs_freepa(tag_headers);
srs_freepa(iovss_cache);
srs_freepa(ppts);
#endif
}

Expand Down Expand Up @@ -489,7 +489,7 @@ int SrsFlvEncoder::write_tags(SrsSharedPtrMessage** msgs, int count)
int nb_iovss = 3 * count;
iovec* iovss = iovss_cache;
if (nb_iovss_cache < nb_iovss) {
srs_freep(iovss_cache);
srs_freepa(iovss_cache);

nb_iovss_cache = nb_iovss;
iovss = iovss_cache = new iovec[nb_iovss];
Expand All @@ -498,7 +498,7 @@ int SrsFlvEncoder::write_tags(SrsSharedPtrMessage** msgs, int count)
// realloc the tag headers.
char* cache = tag_headers;
if (nb_tag_headers < count) {
srs_freep(tag_headers);
srs_freepa(tag_headers);

nb_tag_headers = count;
cache = tag_headers = new char[SRS_FLV_TAG_HEADER_SIZE * count];
Expand All @@ -507,7 +507,7 @@ int SrsFlvEncoder::write_tags(SrsSharedPtrMessage** msgs, int count)
// realloc the pts.
char* pts = ppts;
if (nb_ppts < count) {
srs_freep(ppts);
srs_freepa(ppts);

nb_ppts = count;
pts = ppts = new char[SRS_FLV_PREVIOUS_TAG_SIZE * count];
Expand Down
24 changes: 12 additions & 12 deletions trunk/src/kernel/srs_kernel_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ SrsTsAdaptationField::SrsTsAdaptationField(SrsTsPacket* pkt)

SrsTsAdaptationField::~SrsTsAdaptationField()
{
srs_freep(transport_private_data);
srs_freepa(transport_private_data);
}

int SrsTsAdaptationField::decode(SrsBuffer* stream)
Expand Down Expand Up @@ -1052,7 +1052,7 @@ int SrsTsAdaptationField::decode(SrsBuffer* stream)
srs_error("ts: demux af transport_private_data_flag failed. ret=%d", ret);
return ret;
}
srs_freep(transport_private_data);
srs_freepa(transport_private_data);
transport_private_data = new char[transport_private_data_length];
stream->read_bytes(transport_private_data, transport_private_data_length);
}
Expand Down Expand Up @@ -1337,9 +1337,9 @@ SrsTsPayloadPES::SrsTsPayloadPES(SrsTsPacket* p) : SrsTsPayload(p)

SrsTsPayloadPES::~SrsTsPayloadPES()
{
srs_freep(PES_private_data);
srs_freep(pack_field);
srs_freep(PES_extension_field);
srs_freepa(PES_private_data);
srs_freepa(pack_field);
srs_freepa(PES_extension_field);
}

int SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
Expand Down Expand Up @@ -1616,7 +1616,7 @@ int SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)

// 16B
if (PES_private_data_flag) {
srs_freep(PES_private_data);
srs_freepa(PES_private_data);
PES_private_data = new char[16];
stream->read_bytes(PES_private_data, 16);
}
Expand All @@ -1632,7 +1632,7 @@ int SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
srs_error("ts: demux PSE ext pack failed. ret=%d", ret);
return ret;
}
srs_freep(pack_field);
srs_freepa(pack_field);
pack_field = new char[pack_field_length];
stream->read_bytes(pack_field, pack_field_length);
}
Expand Down Expand Up @@ -1670,7 +1670,7 @@ int SrsTsPayloadPES::decode(SrsBuffer* stream, SrsTsMessage** ppmsg)
srs_error("ts: demux PSE ext field failed. ret=%d", ret);
return ret;
}
srs_freep(PES_extension_field);
srs_freepa(PES_extension_field);
PES_extension_field = new char[PES_extension_field_length];
stream->read_bytes(PES_extension_field, PES_extension_field_length);
}
Expand Down Expand Up @@ -2433,7 +2433,7 @@ SrsTsPayloadPMTESInfo::SrsTsPayloadPMTESInfo(SrsTsStream st, int16_t epid)

SrsTsPayloadPMTESInfo::~SrsTsPayloadPMTESInfo()
{
srs_freep(ES_info);
srs_freepa(ES_info);
}

int SrsTsPayloadPMTESInfo::decode(SrsBuffer* stream)
Expand Down Expand Up @@ -2463,7 +2463,7 @@ int SrsTsPayloadPMTESInfo::decode(SrsBuffer* stream)
srs_error("ts: demux PMT es info data failed. ret=%d", ret);
return ret;
}
srs_freep(ES_info);
srs_freepa(ES_info);
ES_info = new char[ES_info_length];
stream->read_bytes(ES_info, ES_info_length);
}
Expand Down Expand Up @@ -2520,7 +2520,7 @@ SrsTsPayloadPMT::SrsTsPayloadPMT(SrsTsPacket* p) : SrsTsPayloadPSI(p)

SrsTsPayloadPMT::~SrsTsPayloadPMT()
{
srs_freep(program_info_desc);
srs_freepa(program_info_desc);

std::vector<SrsTsPayloadPMTESInfo*>::iterator it;
for (it = infos.begin(); it != infos.end(); ++it) {
Expand Down Expand Up @@ -2574,7 +2574,7 @@ int SrsTsPayloadPMT::psi_decode(SrsBuffer* stream)
return ret;
}

srs_freep(program_info_desc);
srs_freepa(program_info_desc);
program_info_desc = new char[program_info_length];
stream->read_bytes(program_info_desc, program_info_length);
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/libs/srs_librtmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,7 @@ int srs_human_print_rtmp_packet4(char type, u_int32_t timestamp, char* data, int

char* amf0_str = NULL;
srs_human_raw("%s", srs_human_amf0_print(amf0, &amf0_str, NULL));
srs_freep(amf0_str);
srs_freepa(amf0_str);
}
} else {
srs_human_trace("Rtmp packet id=%"PRId64"/%.1f/%.1f, type=%#x, dts=%d, pts=%d, ndiff=%d, diff=%d, size=%d",
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/protocol/srs_http_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ ISrsHttpMessage::ISrsHttpMessage()

ISrsHttpMessage::~ISrsHttpMessage()
{
srs_freep(_http_ts_send_buffer);
srs_freepa(_http_ts_send_buffer);
}

char* ISrsHttpMessage::http_ts_send_buffer()
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/protocol/srs_protocol_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int srs_rtmp_create_msg(char type, u_int32_t timestamp, char* data, int size, in

// only when failed, we must free the data.
if ((ret = srs_do_rtmp_create_msg(type, timestamp, data, size, stream_id, ppmsg)) != ERROR_SUCCESS) {
srs_freep(data);
srs_freepa(data);
return ret;
}

Expand Down
Loading

1 comment on commit 8cec06e

@winlinvip
Copy link
Member Author

Choose a reason for hiding this comment

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

for #515

Please sign in to comment.