Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-11-02 11:26:37 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f4f76cd19646cadfd92b685a525e0261153db63f
f4f76cd1
1 parent
2af77497
for #515, use SrsAutoFreeA to free the array.
隐藏空白字符变更
内嵌
并排对比
正在显示
13 个修改的文件
包含
53 行增加
和
36 行删除
trunk/src/app/srs_app_caster_flv.cpp
trunk/src/app/srs_app_dvr.cpp
trunk/src/app/srs_app_hds.cpp
trunk/src/app/srs_app_http_conn.cpp
trunk/src/app/srs_app_http_hooks.cpp
trunk/src/app/srs_app_http_static.cpp
trunk/src/app/srs_app_mpegts_udp.cpp
trunk/src/core/srs_core_autofree.hpp
trunk/src/kernel/srs_kernel_codec.cpp
trunk/src/kernel/srs_kernel_ts.cpp
trunk/src/protocol/srs_raw_avc.cpp
trunk/src/protocol/srs_rtmp_handshake.cpp
trunk/src/protocol/srs_rtsp_stack.cpp
trunk/src/app/srs_app_caster_flv.cpp
查看文件 @
f4f76cd
...
...
@@ -148,7 +148,7 @@ int SrsDynamicHttpConn::proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std
srs_trace
(
"flv: proxy %s to %s"
,
r
->
uri
().
c_str
(),
output
.
c_str
());
char
*
buffer
=
new
char
[
SRS_HTTP_FLV_STREAM_BUFFER
];
SrsAutoFree
(
char
,
buffer
);
SrsAutoFree
A
(
char
,
buffer
);
ISrsHttpResponseReader
*
rr
=
r
->
body_reader
();
SrsHttpFileReader
reader
(
rr
);
...
...
trunk/src/app/srs_app_dvr.cpp
查看文件 @
f4f76cd
...
...
@@ -240,7 +240,7 @@ int SrsFlvSegment::write_metadata(SrsSharedPtrMessage* metadata)
int
size
=
name
->
total_size
()
+
obj
->
total_size
();
char
*
payload
=
new
char
[
size
];
SrsAutoFree
(
char
,
payload
);
SrsAutoFree
A
(
char
,
payload
);
// 11B flv header, 3B object EOF, 8B number value, 1B number flag.
duration_offset
=
fs
->
tellg
()
+
size
+
11
-
SrsAmf0Size
::
object_eof
()
-
SrsAmf0Size
::
number
();
...
...
@@ -355,7 +355,7 @@ int SrsFlvSegment::update_flv_metadata()
// buffer to write the size.
char
*
buf
=
new
char
[
SrsAmf0Size
::
number
()];
SrsAutoFree
(
char
,
buf
);
SrsAutoFree
A
(
char
,
buf
);
SrsStream
stream
;
if
((
ret
=
stream
.
initialize
(
buf
,
SrsAmf0Size
::
number
()))
!=
ERROR_SUCCESS
)
{
...
...
trunk/src/app/srs_app_hds.cpp
查看文件 @
f4f76cd
...
...
@@ -482,7 +482,7 @@ int SrsHds::flush_bootstrap()
int
size
=
1024
*
100
;
char
*
start_abst
=
new
char
[
1024
*
100
];
SrsAutoFree
(
char
,
start_abst
);
SrsAutoFree
A
(
char
,
start_abst
);
int
size_abst
=
0
;
char
*
start_asrt
=
NULL
;
...
...
trunk/src/app/srs_app_http_conn.cpp
查看文件 @
f4f76cd
...
...
@@ -734,7 +734,7 @@ int SrsHttpMessage::body_read_all(string& body)
// cache to read.
char
*
buf
=
new
char
[
SRS_HTTP_READ_CACHE_BYTES
];
SrsAutoFree
(
char
,
buf
);
SrsAutoFree
A
(
char
,
buf
);
// whatever, read util EOF.
while
(
!
_body
->
eof
())
{
...
...
trunk/src/app/srs_app_http_hooks.cpp
查看文件 @
f4f76cd
...
...
@@ -380,7 +380,7 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::
int
nb_buf
=
srs_min
(
nb_notify
,
SRS_HTTP_READ_BUFFER
);
char
*
buf
=
new
char
[
nb_buf
];
SrsAutoFree
(
char
,
buf
);
SrsAutoFree
A
(
char
,
buf
);
int
nb_read
=
0
;
ISrsHttpResponseReader
*
br
=
msg
->
body_reader
();
...
...
trunk/src/app/srs_app_http_static.cpp
查看文件 @
f4f76cd
...
...
@@ -116,7 +116,7 @@ int SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r
}
}
sh_data
=
new
char
[
sh_size
];
SrsAutoFree
(
char
,
sh_data
);
SrsAutoFree
A
(
char
,
sh_data
);
if
((
ret
=
fs
.
read
(
sh_data
,
sh_size
,
NULL
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/app/srs_app_mpegts_udp.cpp
查看文件 @
f4f76cd
...
...
@@ -199,7 +199,7 @@ int SrsMpegtsOverUdp::on_udp_bytes(string host, int port, char* buf, int nb_buf)
buffer->erase(buffer->length());
int nb_fbuf = fr.filesize();
char* fbuf = new char[nb_fbuf];
SrsAutoFree(char, fbuf);
SrsAutoFree
A
(char, fbuf);
if ((ret = fr.read(fbuf, nb_fbuf, NULL)) != ERROR_SUCCESS) {
return ret;
}
...
...
trunk/src/core/srs_core_autofree.hpp
查看文件 @
f4f76cd
...
...
@@ -31,28 +31,41 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp>
/**
* auto free the instance in the current scope, for instance, MyClass* ptr,
* which is a ptr and this class will:
* 1. free the ptr.
* 2. set ptr to NULL.
* Usage:
* MyClass* po = new MyClass();
* // ...... use po
* SrsAutoFree(MyClass, po);
*/
* auto free the instance in the current scope, for instance, MyClass* ptr,
* which is a ptr and this class will:
* 1. free the ptr.
* 2. set ptr to NULL.
*
* Usage:
* MyClass* po = new MyClass();
* // ...... use po
* SrsAutoFree(MyClass, po);
*
* Usage for array:
* MyClass** pa = new MyClass*[size];
* // ....... use pa
* SrsAutoFreeA(MyClass*, pa);
*
* @remark the MyClass can be basic type, for instance, SrsAutoFreeA(char, pstr),
* where the char* pstr = new char[size].
*/
#define SrsAutoFree(className, instance) \
impl__SrsAutoFree<className> _auto_free_##instance(&instance)
impl__SrsAutoFree<className> _auto_free_##instance(&instance, false)
#define SrsAutoFreeA(className, instance) \
impl__SrsAutoFree<className> _auto_free_array_##instance(&instance, true)
template
<
class
T
>
class
impl__SrsAutoFree
{
private
:
T
**
ptr
;
bool
is_array
;
public
:
/**
* auto delete the ptr.
*/
impl__SrsAutoFree
(
T
**
p
)
{
* auto delete the ptr.
*/
impl__SrsAutoFree
(
T
**
p
,
bool
array
)
{
ptr
=
p
;
is_array
=
array
;
}
virtual
~
impl__SrsAutoFree
()
{
...
...
@@ -60,7 +73,11 @@ public:
return
;
}
delete
*
ptr
;
if
(
is_array
)
{
delete
[]
*
ptr
;
}
else
{
delete
*
ptr
;
}
*
ptr
=
NULL
;
}
...
...
trunk/src/kernel/srs_kernel_codec.cpp
查看文件 @
f4f76cd
...
...
@@ -914,7 +914,7 @@ int SrsAvcAacCodec::avc_demux_sps()
// decode the rbsp from sps.
// rbsp[ i ] a raw byte sequence payload is specified as an ordered sequence of bytes.
int8_t
*
rbsp
=
new
int8_t
[
sequenceParameterSetLength
];
SrsAutoFree
(
int8_t
,
rbsp
);
SrsAutoFree
A
(
int8_t
,
rbsp
);
int
nb_rbsp
=
0
;
while
(
!
stream
.
empty
())
{
...
...
trunk/src/kernel/srs_kernel_ts.cpp
查看文件 @
f4f76cd
...
...
@@ -387,7 +387,7 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea
SrsAutoFree
(
SrsTsPacket
,
pkt
);
char
*
buf
=
new
char
[
SRS_TS_PACKET_SIZE
];
SrsAutoFree
(
char
,
buf
);
SrsAutoFree
A
(
char
,
buf
);
// set the left bytes with 0xFF.
int
nb_buf
=
pkt
->
size
();
...
...
@@ -412,7 +412,7 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea
SrsAutoFree
(
SrsTsPacket
,
pkt
);
char
*
buf
=
new
char
[
SRS_TS_PACKET_SIZE
];
SrsAutoFree
(
char
,
buf
);
SrsAutoFree
A
(
char
,
buf
);
// set the left bytes with 0xFF.
int
nb_buf
=
pkt
->
size
();
...
...
@@ -485,7 +485,7 @@ int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t p
SrsAutoFree
(
SrsTsPacket
,
pkt
);
char
*
buf
=
new
char
[
SRS_TS_PACKET_SIZE
];
SrsAutoFree
(
char
,
buf
);
SrsAutoFree
A
(
char
,
buf
);
// set the left bytes with 0xFF.
int
nb_buf
=
pkt
->
size
();
...
...
trunk/src/protocol/srs_raw_avc.cpp
查看文件 @
f4f76cd
...
...
@@ -157,7 +157,7 @@ int SrsRawH264Stream::mux_sequence_header(string sps, string pps, u_int32_t dts,
+
3
+
(
int
)
sps
.
length
()
+
3
+
(
int
)
pps
.
length
();
char
*
packet
=
new
char
[
nb_packet
];
SrsAutoFree
(
char
,
packet
);
SrsAutoFree
A
(
char
,
packet
);
// use stream to generate the h264 packet.
SrsStream
stream
;
...
...
@@ -236,7 +236,7 @@ int SrsRawH264Stream::mux_ipb_frame(char* frame, int nb_frame, string& ibp)
// NALUnit
int
nb_packet
=
4
+
nb_frame
;
char
*
packet
=
new
char
[
nb_packet
];
SrsAutoFree
(
char
,
packet
);
SrsAutoFree
A
(
char
,
packet
);
// use stream to generate the h264 packet.
SrsStream
stream
;
...
...
trunk/src/protocol/srs_rtmp_handshake.cpp
查看文件 @
f4f76cd
...
...
@@ -487,7 +487,7 @@ namespace _srs_internal
}
srs_assert
(
c1_digest
!=
NULL
);
SrsAutoFree
(
char
,
c1_digest
);
SrsAutoFree
A
(
char
,
c1_digest
);
memcpy
(
digest
.
digest
,
c1_digest
,
32
);
...
...
@@ -506,7 +506,7 @@ namespace _srs_internal
}
srs_assert
(
c1_digest
!=
NULL
);
SrsAutoFree
(
char
,
c1_digest
);
SrsAutoFree
A
(
char
,
c1_digest
);
is_valid
=
srs_bytes_equals
(
digest
.
digest
,
c1_digest
,
32
);
...
...
@@ -546,7 +546,7 @@ namespace _srs_internal
srs_verbose
(
"calc s1 digest success."
);
srs_assert
(
s1_digest
!=
NULL
);
SrsAutoFree
(
char
,
s1_digest
);
SrsAutoFree
A
(
char
,
s1_digest
);
memcpy
(
digest
.
digest
,
s1_digest
,
32
);
srs_verbose
(
"copy s1 key success."
);
...
...
@@ -566,7 +566,7 @@ namespace _srs_internal
}
srs_assert
(
s1_digest
!=
NULL
);
SrsAutoFree
(
char
,
s1_digest
);
SrsAutoFree
A
(
char
,
s1_digest
);
is_valid
=
srs_bytes_equals
(
digest
.
digest
,
s1_digest
,
32
);
...
...
@@ -585,7 +585,7 @@ namespace _srs_internal
* @return a new allocated bytes, user must free it.
*/
char
*
c1s1_joined_bytes
=
new
char
[
1536
-
32
];
SrsAutoFree
(
char
,
c1s1_joined_bytes
);
SrsAutoFree
A
(
char
,
c1s1_joined_bytes
);
if
((
ret
=
copy_to
(
owner
,
c1s1_joined_bytes
,
1536
-
32
,
false
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -613,7 +613,7 @@ namespace _srs_internal
* @return a new allocated bytes, user must free it.
*/
char
*
c1s1_joined_bytes
=
new
char
[
1536
-
32
];
SrsAutoFree
(
char
,
c1s1_joined_bytes
);
SrsAutoFree
A
(
char
,
c1s1_joined_bytes
);
if
((
ret
=
copy_to
(
owner
,
c1s1_joined_bytes
,
1536
-
32
,
false
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/protocol/srs_rtsp_stack.cpp
查看文件 @
f4f76cd
...
...
@@ -548,7 +548,7 @@ int SrsRtspSdp::parse_fmtp_attribute(string attr)
}
char
*
tmp_sh
=
new
char
[
item_value
.
length
()];
SrsAutoFree
(
char
,
tmp_sh
);
SrsAutoFree
A
(
char
,
tmp_sh
);
int
nb_tmp_sh
=
ff_hex_to_data
((
u_int8_t
*
)
tmp_sh
,
item_value
.
c_str
());
srs_assert
(
nb_tmp_sh
>
0
);
audio_sh
.
append
(
tmp_sh
,
nb_tmp_sh
);
...
...
@@ -603,7 +603,7 @@ string SrsRtspSdp::base64_decode(string value)
int
nb_output
=
(
int
)(
value
.
length
()
*
2
);
u_int8_t
*
output
=
new
u_int8_t
[
nb_output
];
SrsAutoFree
(
u_int8_t
,
output
);
SrsAutoFree
A
(
u_int8_t
,
output
);
int
ret
=
srs_av_base64_decode
(
output
,
(
char
*
)
value
.
c_str
(),
nb_output
);
if
(
ret
<=
0
)
{
...
...
请
注册
或
登录
后发表评论