@@ -300,6 +300,9 @@ ngx_rtmp_live_merge_app_conf(ngx_conf_t *cf, void *parent, void *child)
300300
301301 conf -> streams = ngx_pcalloc (cf -> pool ,
302302 sizeof (ngx_rtmp_live_stream_t * ) * conf -> nbuckets );
303+ if (conf -> streams == NULL ) {
304+ return NGX_CONF_ERROR ;
305+ }
303306
304307 return NGX_CONF_OK ;
305308}
@@ -360,6 +363,11 @@ ngx_rtmp_live_get_stream(ngx_rtmp_session_t *s, u_char *name, int create)
360363 lacf -> free_streams = lacf -> free_streams -> next ;
361364 } else {
362365 * stream = ngx_palloc (lacf -> pool , sizeof (ngx_rtmp_live_stream_t ));
366+ if (* stream == NULL ) {
367+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
368+ "live: failed to allocate for stream" );
369+ return NULL ;
370+ }
363371 }
364372 ngx_memzero (* stream , sizeof (ngx_rtmp_live_stream_t ));
365373 ngx_memcpy ((* stream )-> name , name ,
@@ -624,8 +632,22 @@ ngx_rtmp_live_join(ngx_rtmp_session_t *s, u_char *name, unsigned publisher)
624632 if (ctx == NULL ) {
625633 ctx = ngx_palloc (s -> connection -> pool , sizeof (ngx_rtmp_live_ctx_t ));
626634 if (ctx == NULL ) {
627- ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
628- "live: failed to allocate for ctx" );
635+ if (publisher ) {
636+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
637+ "live: failed to allocate for publish ctx" );
638+
639+ ngx_rtmp_send_status (s , "NetStream.Publish.Failed" , "error" ,
640+ "Failed to allocate memory" );
641+ } else {
642+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
643+ "live: failed to allocate for play ctx" );
644+
645+ ngx_rtmp_send_status (s , "NetStream.Play.Failed" , "error" ,
646+ "Failed to allocate memory" );
647+ }
648+
649+ ngx_rtmp_finalize_session (s );
650+
629651 return ;
630652 }
631653
@@ -1429,22 +1451,27 @@ ngx_rtmp_live_on_fcpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
14291451
14301452 lacf = ngx_rtmp_get_module_app_conf (s , ngx_rtmp_live_module );
14311453 if (lacf == NULL ) {
1432- ngx_log_error (NGX_LOG_DEBUG , s -> connection -> log , 0 ,
1454+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
14331455 "live: FCPublish - no live config!" );
14341456 return NGX_ERROR ;
14351457 }
14361458
14371459 if (!lacf -> live || in == NULL || in -> buf == NULL ) {
1438- ngx_log_error ( NGX_LOG_DEBUG , s -> connection -> log , 0 ,
1460+ ngx_log_debug0 ( NGX_LOG_DEBUG_RTMP , s -> connection -> log , 0 ,
14391461 "live: FCPublish - no live or no buffer!" );
14401462 return NGX_OK ;
14411463 }
14421464
14431465 ngx_memzero (& v , sizeof (v ));
1444- ngx_rtmp_receive_amf (s , in , in_elts ,
1445- sizeof (in_elts ) / sizeof (in_elts [0 ]));
1466+ if (ngx_rtmp_receive_amf (s , in , in_elts ,
1467+ sizeof (in_elts ) / sizeof (in_elts [0 ])))
1468+ {
1469+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
1470+ "live: FCPublish - error receiving amf data" );
1471+ return NGX_ERROR ;
1472+ }
14461473
1447- ngx_log_error ( NGX_LOG_DEBUG , s -> connection -> log , 0 ,
1474+ ngx_log_debug1 ( NGX_LOG_DEBUG_RTMP , s -> connection -> log , 0 ,
14481475 "live: onFCPublish: stream='%s'" , v .stream );
14491476
14501477 return ngx_rtmp_send_fcpublish (s , v .stream );
@@ -1480,22 +1507,27 @@ ngx_rtmp_live_on_fcunpublish(ngx_rtmp_session_t *s, ngx_rtmp_header_t *h,
14801507
14811508 lacf = ngx_rtmp_get_module_app_conf (s , ngx_rtmp_live_module );
14821509 if (lacf == NULL ) {
1483- ngx_log_error (NGX_LOG_DEBUG , s -> connection -> log , 0 ,
1510+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
14841511 "live: FCUnpublish - no live config!" );
14851512 return NGX_ERROR ;
14861513 }
14871514
14881515 if (!lacf -> live || in == NULL || in -> buf == NULL ) {
1489- ngx_log_error ( NGX_LOG_DEBUG , s -> connection -> log , 0 ,
1516+ ngx_log_debug0 ( NGX_LOG_DEBUG_RTMP , s -> connection -> log , 0 ,
14901517 "live: FCUnpublish - no live or no buffer!" );
14911518 return NGX_OK ;
14921519 }
14931520
14941521 ngx_memzero (& v , sizeof (v ));
1495- ngx_rtmp_receive_amf (s , in , in_elts ,
1496- sizeof (in_elts ) / sizeof (in_elts [0 ]));
1522+ if (ngx_rtmp_receive_amf (s , in , in_elts ,
1523+ sizeof (in_elts ) / sizeof (in_elts [0 ])))
1524+ {
1525+ ngx_log_error (NGX_LOG_ERR , s -> connection -> log , 0 ,
1526+ "live: FCUnpublish - error receiving amf data" );
1527+ return NGX_ERROR ;
1528+ }
14971529
1498- ngx_log_error ( NGX_LOG_DEBUG , s -> connection -> log , 0 ,
1530+ ngx_log_debug1 ( NGX_LOG_DEBUG_RTMP , s -> connection -> log , 0 ,
14991531 "live: onFCUnpublish: stream='%s'" , v .stream );
15001532
15011533 return ngx_rtmp_send_fcunpublish (s , v .stream );
0 commit comments