Skip to content

Commit 4336edf

Browse files
committed
[fix] fix some memory leak bugs.
1 parent f690cd5 commit 4336edf

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

ngx_rtmp_live_module.c

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,6 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
797797
ngx_rtmp_codec_ctx_t *codec_ctx;
798798
ngx_chain_t *header, *coheader, *meta,
799799
*apkt, *acopkt, *rpkt;
800-
ngx_rtmp_core_srv_conf_t *cscf;
801800
ngx_rtmp_live_app_conf_t *lacf;
802801
ngx_rtmp_session_t *ss;
803802
ngx_rtmp_header_t ch, lh, clh;
@@ -863,8 +862,6 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
863862
prio = (h->type == NGX_RTMP_MSG_VIDEO ?
864863
ngx_rtmp_get_video_frame_type(in) : 0);
865864

866-
cscf = ngx_rtmp_get_module_srv_conf(s, ngx_rtmp_core_module);
867-
868865
csidx = !(lacf->interleave || h->type == NGX_RTMP_MSG_VIDEO);
869866

870867
cs = &ctx->cs[csidx];
@@ -951,16 +948,6 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
951948

952949
handler = ngx_rtmp_process_handlers[pctx->protocol];
953950

954-
if (rpkt) {
955-
ngx_rtmp_free_shared_chain(cscf, rpkt);
956-
}
957-
958-
rpkt = handler->append_message_pt(ss, &ch, &lh, in);
959-
if (rpkt == NULL) {
960-
/* request from http closed */
961-
continue;
962-
}
963-
964951
/* send metadata */
965952

966953
if (codec_ctx) {
@@ -969,7 +956,6 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
969956
if (r == NULL
970957
|| (r->connection && r->connection->destroyed))
971958
{
972-
ngx_rtmp_free_shared_chain(cscf, rpkt);
973959
continue;
974960
}
975961

@@ -979,7 +965,6 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
979965
if ((!codec_ctx->has_video || !codec_ctx->has_audio)
980966
&& !codec_ctx->pure_audio)
981967
{
982-
ngx_rtmp_free_shared_chain(cscf, rpkt);
983968
continue;
984969
}
985970

@@ -1001,7 +986,7 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
1001986
pctx->meta_version = meta_version;
1002987
}
1003988

1004-
handler->free_message_pt(s, meta);
989+
handler->free_message_pt(ss, meta);
1005990
meta = NULL;
1006991
}
1007992

@@ -1056,6 +1041,11 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
10561041

10571042
rc = handler->send_message_pt(ss, apkt, 0);
10581043
if (rc != NGX_OK) {
1044+
if (apkt) {
1045+
handler->free_message_pt(ss, apkt);
1046+
apkt = NULL;
1047+
}
1048+
10591049
continue;
10601050
}
10611051
}
@@ -1067,6 +1057,11 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
10671057

10681058
rc = handler->send_message_pt(ss, acopkt, 0);
10691059
if (rc != NGX_OK) {
1060+
if (acopkt) {
1061+
handler->free_message_pt(ss, acopkt);
1062+
acopkt = NULL;
1063+
}
1064+
10701065
continue;
10711066
}
10721067

@@ -1090,6 +1085,11 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
10901085

10911086
rc = handler->send_message_pt(ss, apkt, prio);
10921087
if (rc != NGX_OK) {
1088+
if (apkt) {
1089+
handler->free_message_pt(ss, apkt);
1090+
apkt = NULL;
1091+
}
1092+
10931093
continue;
10941094
}
10951095

@@ -1103,6 +1103,12 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
11031103
}
11041104
}
11051105

1106+
rpkt = handler->append_message_pt(ss, &ch, &lh, in);
1107+
if (rpkt == NULL) {
1108+
/* request from http closed */
1109+
continue;
1110+
}
1111+
11061112
/* send relative packet */
11071113

11081114
ngx_log_debug2(NGX_LOG_DEBUG_RTMP, ss->connection->log, 0,
@@ -1114,6 +1120,16 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
11141120

11151121
cs->dropped += delta;
11161122

1123+
if (apkt) {
1124+
handler->free_message_pt(ss, apkt);
1125+
apkt = NULL;
1126+
}
1127+
1128+
if (acopkt) {
1129+
handler->free_message_pt(ss, acopkt);
1130+
acopkt = NULL;
1131+
}
1132+
11171133
if (mandatory) {
11181134
ngx_log_debug0(NGX_LOG_DEBUG_RTMP, ss->connection->log, 0,
11191135
"live: mandatory packet failed");
@@ -1126,18 +1142,21 @@ ngx_rtmp_live_av(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
11261142
cs->timestamp += delta;
11271143
++peers;
11281144
ss->current_time = cs->timestamp;
1129-
}
11301145

1131-
if (rpkt) {
1132-
ngx_rtmp_free_shared_chain(cscf, rpkt);
1133-
}
1146+
if (rpkt) {
1147+
handler->free_message_pt(ss, rpkt);
1148+
rpkt = NULL;
1149+
}
11341150

1135-
if (apkt) {
1136-
ngx_rtmp_free_shared_chain(cscf, apkt);
1137-
}
1151+
if (apkt) {
1152+
handler->free_message_pt(ss, apkt);
1153+
apkt = NULL;
1154+
}
11381155

1139-
if (acopkt) {
1140-
ngx_rtmp_free_shared_chain(cscf, acopkt);
1156+
if (acopkt) {
1157+
handler->free_message_pt(ss, acopkt);
1158+
acopkt = NULL;
1159+
}
11411160
}
11421161

11431162
ngx_rtmp_update_bandwidth(&ctx->stream->bw_in, h->mlen);

0 commit comments

Comments
 (0)