diff --git a/trunk/src/app/srs_app_caster_flv.cpp b/trunk/src/app/srs_app_caster_flv.cpp index 1a05c87145..a1b8f6f406 100644 --- a/trunk/src/app/srs_app_caster_flv.cpp +++ b/trunk/src/app/srs_app_caster_flv.cpp @@ -205,7 +205,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); } diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 92e3640438..271f2cea4f 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -433,7 +433,7 @@ int SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector& args, if (!word_str.empty()) { args.push_back(word_str); } - srs_freep(aword); + srs_freepa(aword); if (ch == ';') { return ERROR_SYSTEM_CONFIG_DIRECTIVE; @@ -4488,7 +4488,7 @@ namespace _srs_internal SrsConfigBuffer::~SrsConfigBuffer() { - srs_freep(start); + srs_freepa(start); } int SrsConfigBuffer::fullfill(const char* filename) @@ -4507,7 +4507,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; diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 9b36bec8bc..1a378dd764 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -76,7 +76,7 @@ SrsHttpResponseWriter::SrsHttpResponseWriter(SrsStSocket* io) SrsHttpResponseWriter::~SrsHttpResponseWriter() { srs_freep(hdr); - srs_freep(iovss_cache); + srs_freepa(iovss_cache); } int SrsHttpResponseWriter::final_request() @@ -188,7 +188,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]; } @@ -506,7 +506,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, http_parser* header, SrsFastBuffer* body, vector& headers) diff --git a/trunk/src/app/srs_app_listener.cpp b/trunk/src/app/srs_app_listener.cpp index 2648ab95cc..6df39fea7f 100644 --- a/trunk/src/app/srs_app_listener.cpp +++ b/trunk/src/app/srs_app_listener.cpp @@ -94,7 +94,7 @@ SrsUdpListener::~SrsUdpListener() // close it manually. close(_fd); - srs_freep(buf); + srs_freepa(buf); } int SrsUdpListener::fd() diff --git a/trunk/src/app/srs_app_log.cpp b/trunk/src/app/srs_app_log.cpp index 2062b17765..b6c8162ad3 100644 --- a/trunk/src/app/srs_app_log.cpp +++ b/trunk/src/app/srs_app_log.cpp @@ -91,7 +91,7 @@ SrsFastLog::SrsFastLog() SrsFastLog::~SrsFastLog() { - srs_freep(log_data); + srs_freepa(log_data); if (fd > 0) { ::close(fd); diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 6c581166c1..52abff519a 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -161,7 +161,7 @@ SrsFastVector::SrsFastVector() SrsFastVector::~SrsFastVector() { free(); - srs_freep(msgs); + srs_freepa(msgs); } int SrsFastVector::size() @@ -220,7 +220,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; } diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index d059c1afaf..59c06d5f0a 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -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, diff --git a/trunk/src/kernel/srs_kernel_codec.cpp b/trunk/src/kernel/srs_kernel_codec.cpp index 875f4ef264..5c557209bf 100644 --- a/trunk/src/kernel/srs_kernel_codec.cpp +++ b/trunk/src/kernel/srs_kernel_codec.cpp @@ -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() @@ -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); @@ -764,7 +764,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsStream* 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); } @@ -825,7 +825,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsStream* stream) return ret; } if (sequenceParameterSetLength > 0) { - srs_freep(sequenceParameterSetNALUnit); + srs_freepa(sequenceParameterSetNALUnit); sequenceParameterSetNALUnit = new char[sequenceParameterSetLength]; stream->read_bytes(sequenceParameterSetNALUnit, sequenceParameterSetLength); } @@ -854,7 +854,7 @@ int SrsAvcAacCodec::avc_demux_sps_pps(SrsStream* stream) return ret; } if (pictureParameterSetLength > 0) { - srs_freep(pictureParameterSetNALUnit); + srs_freepa(pictureParameterSetNALUnit); pictureParameterSetNALUnit = new char[pictureParameterSetLength]; stream->read_bytes(pictureParameterSetNALUnit, pictureParameterSetLength); } diff --git a/trunk/src/kernel/srs_kernel_flv.cpp b/trunk/src/kernel/srs_kernel_flv.cpp index aedbee6a78..760956fb43 100644 --- a/trunk/src/kernel/srs_kernel_flv.cpp +++ b/trunk/src/kernel/srs_kernel_flv.cpp @@ -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); @@ -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() @@ -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 } @@ -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]; @@ -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]; @@ -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]; diff --git a/trunk/src/kernel/srs_kernel_ts.cpp b/trunk/src/kernel/srs_kernel_ts.cpp index e0a9961a6f..c9d795a58d 100644 --- a/trunk/src/kernel/srs_kernel_ts.cpp +++ b/trunk/src/kernel/srs_kernel_ts.cpp @@ -915,7 +915,7 @@ SrsTsAdaptationField::SrsTsAdaptationField(SrsTsPacket* pkt) SrsTsAdaptationField::~SrsTsAdaptationField() { - srs_freep(transport_private_data); + srs_freepa(transport_private_data); } int SrsTsAdaptationField::decode(SrsStream* stream) @@ -1040,7 +1040,7 @@ int SrsTsAdaptationField::decode(SrsStream* 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); } @@ -1325,9 +1325,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(SrsStream* stream, SrsTsMessage** ppmsg) @@ -1604,7 +1604,7 @@ int SrsTsPayloadPES::decode(SrsStream* 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); } @@ -1620,7 +1620,7 @@ int SrsTsPayloadPES::decode(SrsStream* 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); } @@ -1658,7 +1658,7 @@ int SrsTsPayloadPES::decode(SrsStream* 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); } @@ -2421,7 +2421,7 @@ SrsTsPayloadPMTESInfo::SrsTsPayloadPMTESInfo(SrsTsStream st, int16_t epid) SrsTsPayloadPMTESInfo::~SrsTsPayloadPMTESInfo() { - srs_freep(ES_info); + srs_freepa(ES_info); } int SrsTsPayloadPMTESInfo::decode(SrsStream* stream) @@ -2451,7 +2451,7 @@ int SrsTsPayloadPMTESInfo::decode(SrsStream* 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); } @@ -2508,7 +2508,7 @@ SrsTsPayloadPMT::SrsTsPayloadPMT(SrsTsPacket* p) : SrsTsPayloadPSI(p) SrsTsPayloadPMT::~SrsTsPayloadPMT() { - srs_freep(program_info_desc); + srs_freepa(program_info_desc); std::vector::iterator it; for (it = infos.begin(); it != infos.end(); ++it) { @@ -2562,7 +2562,7 @@ int SrsTsPayloadPMT::psi_decode(SrsStream* 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); } diff --git a/trunk/src/libs/srs_librtmp.cpp b/trunk/src/libs/srs_librtmp.cpp index 21851bcdb0..88ffeada6f 100644 --- a/trunk/src/libs/srs_librtmp.cpp +++ b/trunk/src/libs/srs_librtmp.cpp @@ -2398,7 +2398,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", diff --git a/trunk/src/protocol/srs_http_stack.cpp b/trunk/src/protocol/srs_http_stack.cpp index fb143805da..f88c08f68e 100755 --- a/trunk/src/protocol/srs_http_stack.cpp +++ b/trunk/src/protocol/srs_http_stack.cpp @@ -774,7 +774,7 @@ ISrsHttpMessage::ISrsHttpMessage() ISrsHttpMessage::~ISrsHttpMessage() { - srs_freep(_http_ts_send_buffer); + srs_freepa(_http_ts_send_buffer); } char* ISrsHttpMessage::http_ts_send_buffer() diff --git a/trunk/src/protocol/srs_rtmp_handshake.cpp b/trunk/src/protocol/srs_rtmp_handshake.cpp index d4fbae69b4..3d94c7d70b 100644 --- a/trunk/src/protocol/srs_rtmp_handshake.cpp +++ b/trunk/src/protocol/srs_rtmp_handshake.cpp @@ -319,8 +319,8 @@ namespace _srs_internal key_block::~key_block() { - srs_freep(random0); - srs_freep(random1); + srs_freepa(random0); + srs_freepa(random1); } int key_block::parse(SrsStream* stream) @@ -342,7 +342,7 @@ namespace _srs_internal random0_size = valid_offset; if (random0_size > 0) { - srs_freep(random0); + srs_freepa(random0); random0 = new char[random0_size]; stream->read_bytes(random0, random0_size); } @@ -351,7 +351,7 @@ namespace _srs_internal random1_size = 764 - valid_offset - 128 - 4; if (random1_size > 0) { - srs_freep(random1); + srs_freepa(random1); random1 = new char[random1_size]; stream->read_bytes(random1, random1_size); } @@ -401,8 +401,8 @@ namespace _srs_internal digest_block::~digest_block() { - srs_freep(random0); - srs_freep(random1); + srs_freepa(random0); + srs_freepa(random1); } int digest_block::parse(SrsStream* stream) @@ -419,7 +419,7 @@ namespace _srs_internal random0_size = valid_offset; if (random0_size > 0) { - srs_freep(random0); + srs_freepa(random0); random0 = new char[random0_size]; stream->read_bytes(random0, random0_size); } @@ -428,7 +428,7 @@ namespace _srs_internal random1_size = 764 - 4 - valid_offset - 32; if (random1_size > 0) { - srs_freep(random1); + srs_freepa(random1); random1 = new char[random1_size]; stream->read_bytes(random1, random1_size); } @@ -592,7 +592,7 @@ namespace _srs_internal c1_digest = new char[SRS_OpensslHashSize]; if ((ret = openssl_HMACsha256(SrsGenuineFPKey, 30, c1s1_joined_bytes, 1536 - 32, c1_digest)) != ERROR_SUCCESS) { - srs_freep(c1_digest); + srs_freepa(c1_digest); srs_error("calc digest for c1 failed. ret=%d", ret); return ret; } @@ -620,7 +620,7 @@ namespace _srs_internal s1_digest = new char[SRS_OpensslHashSize]; if ((ret = openssl_HMACsha256(SrsGenuineFMSKey, 36, c1s1_joined_bytes, 1536 - 32, s1_digest)) != ERROR_SUCCESS) { - srs_freep(s1_digest); + srs_freepa(s1_digest); srs_error("calc digest for s1 failed. ret=%d", ret); return ret; } diff --git a/trunk/src/protocol/srs_rtmp_msg_array.cpp b/trunk/src/protocol/srs_rtmp_msg_array.cpp index 047c3b71f1..adeb4138e5 100644 --- a/trunk/src/protocol/srs_rtmp_msg_array.cpp +++ b/trunk/src/protocol/srs_rtmp_msg_array.cpp @@ -40,7 +40,7 @@ SrsMessageArray::~SrsMessageArray() // we just free the msgs itself, // both delete and delete[] is ok, // for each msg in msgs is already freed by send_and_free_messages. - srs_freep(msgs); + srs_freepa(msgs); } void SrsMessageArray::free(int count) diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp index 277309a62a..71d068ee90 100644 --- a/trunk/src/protocol/srs_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_rtmp_stack.cpp @@ -151,14 +151,14 @@ int SrsPacket::encode(int& psize, char*& ppayload) if ((ret = stream.initialize(payload, size)) != ERROR_SUCCESS) { srs_error("initialize the stream failed. ret=%d", ret); - srs_freep(payload); + srs_freepa(payload); return ret; } } if ((ret = encode_packet(&stream)) != ERROR_SUCCESS) { srs_error("encode the packet failed. ret=%d", ret); - srs_freep(payload); + srs_freepa(payload); return ret; } @@ -279,7 +279,7 @@ SrsProtocol::~SrsProtocol() SrsChunkStream* cs = cs_cache[i]; srs_freep(cs); } - srs_freep(cs_cache); + srs_freepa(cs_cache); } void SrsProtocol::set_auto_response(bool v) @@ -632,7 +632,7 @@ int SrsProtocol::do_send_and_free_packet(SrsPacket* packet, int stream_id) header.perfer_cid = packet->get_prefer_cid(); ret = do_simple_send(&header, payload, size); - srs_freep(payload); + srs_freepa(payload); if (ret == ERROR_SUCCESS) { ret = on_send_packet(&header, packet); } @@ -1765,9 +1765,9 @@ SrsHandshakeBytes::SrsHandshakeBytes() SrsHandshakeBytes::~SrsHandshakeBytes() { - srs_freep(c0c1); - srs_freep(s0s1s2); - srs_freep(c2); + srs_freepa(c0c1); + srs_freepa(s0s1s2); + srs_freepa(c2); } int SrsHandshakeBytes::read_c0c1(ISrsProtocolReaderWriter* io) diff --git a/trunk/src/protocol/srs_rtmp_utility.cpp b/trunk/src/protocol/srs_rtmp_utility.cpp index c28d5cf325..408e974bdf 100644 --- a/trunk/src/protocol/srs_rtmp_utility.cpp +++ b/trunk/src/protocol/srs_rtmp_utility.cpp @@ -217,7 +217,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; }