Skip to content

Commit 2357864

Browse files
authored
Cleanup allocated mp streams when janus_streaming_create_rtp_source_stream fails (see #3464) (#3465)
1 parent dadc2ab commit 2357864

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

src/plugins/janus_streaming.c

+18-32
Original file line numberDiff line numberDiff line change
@@ -2206,8 +2206,8 @@ int janus_streaming_init(janus_callbacks *callback, const char *config_path) {
22062206
textdata = FALSE;
22072207
else {
22082208
JANUS_LOG(LOG_ERR, "Can't add 'rtp' mountpoint '%s', invalid data type '%s'...\n", cat->name, dt->value);
2209-
cl = cl->next;
2210-
continue;
2209+
failed = TRUE;
2210+
break;
22112211
}
22122212
}
22132213
const char *streamcodec = (codec && codec->value ? codec->value : NULL);
@@ -2268,6 +2268,7 @@ int janus_streaming_init(janus_callbacks *callback, const char *config_path) {
22682268
ml = ml->next;
22692269
}
22702270
if(failed) {
2271+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
22712272
cl = cl->next;
22722273
continue;
22732274
}
@@ -2460,6 +2461,7 @@ int janus_streaming_init(janus_callbacks *callback, const char *config_path) {
24602461
doaskew, FALSE, FALSE, FALSE, FALSE, FALSE);
24612462
if(stream == NULL) {
24622463
JANUS_LOG(LOG_ERR, "Skipping 'audio' stream '%s', error creating source stream...\n", cat->name);
2464+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
24632465
cl = cl->next;
24642466
continue;
24652467
}
@@ -2485,6 +2487,7 @@ int janus_streaming_init(janus_callbacks *callback, const char *config_path) {
24852487
dovskew, bufferkf, simulcast, dosvc, FALSE, FALSE);
24862488
if(stream == NULL) {
24872489
JANUS_LOG(LOG_ERR, "Skipping 'video' stream '%s', error creating source stream...\n", cat->name);
2490+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
24882491
cl = cl->next;
24892492
continue;
24902493
}
@@ -2505,6 +2508,7 @@ int janus_streaming_init(janus_callbacks *callback, const char *config_path) {
25052508
FALSE, FALSE, FALSE, FALSE, textdata, buffermsg);
25062509
if(stream == NULL) {
25072510
JANUS_LOG(LOG_ERR, "Skipping 'data' stream '%s', error creating source stream...\n", cat->name);
2511+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
25082512
cl = cl->next;
25092513
continue;
25102514
}
@@ -3478,6 +3482,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
34783482
JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream '%s', unsupported media type...\n", (const char *)json_string_value(name));
34793483
error_code = JANUS_STREAMING_ERROR_CANT_CREATE;
34803484
g_snprintf(error_cause, 512, "Unsupported media type in media stream");
3485+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
34813486
janus_mutex_lock(&mountpoints_mutex);
34823487
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
34833488
janus_mutex_unlock(&mountpoints_mutex);
@@ -3518,6 +3523,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
35183523
JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream '%s', invalid network interface configuration for media stream...\n", (const char *)json_string_value(name));
35193524
error_code = JANUS_STREAMING_ERROR_CANT_CREATE;
35203525
g_snprintf(error_cause, 512, ifas ? "Invalid network interface configuration for media stream" : "Unable to query network device information");
3526+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
35213527
janus_mutex_lock(&mountpoints_mutex);
35223528
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
35233529
janus_mutex_unlock(&mountpoints_mutex);
@@ -3558,6 +3564,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
35583564
JANUS_LOG(LOG_ERR, "Invalid element (datatype can only be text or binary)\n");
35593565
error_code = JANUS_STREAMING_ERROR_INVALID_ELEMENT;
35603566
g_snprintf(error_cause, 512, "Invalid element (datatype can only be text or binary)");
3567+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
35613568
janus_mutex_lock(&mountpoints_mutex);
35623569
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
35633570
janus_mutex_unlock(&mountpoints_mutex);
@@ -3575,6 +3582,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
35753582
JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream '%s', error creating data source stream...\n", (const char *)json_string_value(name));
35763583
error_code = JANUS_STREAMING_ERROR_CANT_CREATE;
35773584
g_snprintf(error_cause, 512, "Can't add 'rtp' stream, error creating data source stream");
3585+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
35783586
janus_mutex_lock(&mountpoints_mutex);
35793587
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
35803588
janus_mutex_unlock(&mountpoints_mutex);
@@ -3613,6 +3621,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
36133621
error_code, error_cause, TRUE,
36143622
JANUS_STREAMING_ERROR_MISSING_ELEMENT, JANUS_STREAMING_ERROR_INVALID_ELEMENT);
36153623
if(error_code != 0) {
3624+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
36163625
janus_mutex_lock(&mountpoints_mutex);
36173626
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
36183627
janus_mutex_unlock(&mountpoints_mutex);
@@ -3665,6 +3674,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
36653674
JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream '%s', error creating audio source stream...\n", (const char *)json_string_value(name));
36663675
error_code = JANUS_STREAMING_ERROR_CANT_CREATE;
36673676
g_snprintf(error_cause, 512, "Can't add 'rtp' stream, error creating audio source stream");
3677+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
36683678
janus_mutex_lock(&mountpoints_mutex);
36693679
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
36703680
janus_mutex_unlock(&mountpoints_mutex);
@@ -3683,6 +3693,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
36833693
error_code, error_cause, TRUE,
36843694
JANUS_STREAMING_ERROR_MISSING_ELEMENT, JANUS_STREAMING_ERROR_INVALID_ELEMENT);
36853695
if(error_code != 0) {
3696+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
36863697
janus_mutex_lock(&mountpoints_mutex);
36873698
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
36883699
janus_mutex_unlock(&mountpoints_mutex);
@@ -3753,6 +3764,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
37533764
JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream '%s', error creating video source stream...\n", (const char *)json_string_value(name));
37543765
error_code = JANUS_STREAMING_ERROR_CANT_CREATE;
37553766
g_snprintf(error_cause, 512, "Can't add 'rtp' stream, error creating video source stream");
3767+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
37563768
janus_mutex_lock(&mountpoints_mutex);
37573769
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
37583770
janus_mutex_unlock(&mountpoints_mutex);
@@ -3769,6 +3781,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
37693781
error_code, error_cause, TRUE,
37703782
JANUS_STREAMING_ERROR_MISSING_ELEMENT, JANUS_STREAMING_ERROR_INVALID_ELEMENT);
37713783
if(error_code != 0) {
3784+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
37723785
janus_mutex_lock(&mountpoints_mutex);
37733786
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
37743787
janus_mutex_unlock(&mountpoints_mutex);
@@ -3825,6 +3838,7 @@ static json_t *janus_streaming_process_synchronous_request(janus_streaming_sessi
38253838
JANUS_LOG(LOG_ERR, "Can't add 'rtp' stream '%s', error creating data source stream...\n", (const char *)json_string_value(name));
38263839
error_code = JANUS_STREAMING_ERROR_CANT_CREATE;
38273840
g_snprintf(error_cause, 512, "Can't add 'rtp' stream, error creating data source stream");
3841+
g_list_free_full(streams, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
38283842
janus_mutex_lock(&mountpoints_mutex);
38293843
g_hash_table_remove(mountpoints_temp, string_ids ? (gpointer)mpid_str : (gpointer)&mpid);
38303844
janus_mutex_unlock(&mountpoints_mutex);
@@ -7682,9 +7696,7 @@ janus_streaming_mountpoint *janus_streaming_create_rtp_source(
76827696
if(len < SRTP_MASTER_LENGTH) {
76837697
JANUS_LOG(LOG_ERR, "Invalid SRTP crypto (%s)\n", srtpcrypto);
76847698
g_free(decoded);
7685-
janus_mutex_lock(&mountpoints_mutex);
7686-
g_hash_table_remove(mountpoints_temp, &id);
7687-
janus_mutex_unlock(&mountpoints_mutex);
7699+
g_list_free_full(media, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
76887700
g_free(live_rtp_source);
76897701
g_free(live_rtp->name);
76907702
g_free(live_rtp->description);
@@ -7709,9 +7721,7 @@ janus_streaming_mountpoint *janus_streaming_create_rtp_source(
77097721
/* Something went wrong... */
77107722
JANUS_LOG(LOG_ERR, "Error creating forwarder SRTP session: %d (%s)\n", res, janus_srtp_error_str(res));
77117723
g_free(decoded);
7712-
janus_mutex_lock(&mountpoints_mutex);
7713-
g_hash_table_remove(mountpoints_temp, &id);
7714-
janus_mutex_unlock(&mountpoints_mutex);
7724+
g_list_free_full(media, (GDestroyNotify)(janus_streaming_rtp_source_stream_unref));
77157725
g_free(live_rtp_source);
77167726
g_free(live_rtp->name);
77177727
g_free(live_rtp->description);
@@ -7839,17 +7849,11 @@ janus_streaming_mountpoint *janus_streaming_create_file_source(
78397849
}
78407850
if(!doaudio && !dovideo) {
78417851
JANUS_LOG(LOG_ERR, "Can't add 'file' stream, no audio or video have to be streamed...\n");
7842-
janus_mutex_lock(&mountpoints_mutex);
7843-
g_hash_table_remove(mountpoints_temp, &id);
7844-
janus_mutex_unlock(&mountpoints_mutex);
78457852
return NULL;
78467853
}
78477854
/* FIXME We don't support video streaming from file yet */
78487855
if(!doaudio || dovideo) {
78497856
JANUS_LOG(LOG_ERR, "Can't add 'file' stream, we only support audio file streaming right now...\n");
7850-
janus_mutex_lock(&mountpoints_mutex);
7851-
g_hash_table_remove(mountpoints_temp, &id);
7852-
janus_mutex_unlock(&mountpoints_mutex);
78537857
return NULL;
78547858
}
78557859
/* TODO We should support something more than raw a-Law and mu-Law streams... */
@@ -7860,18 +7864,12 @@ janus_streaming_mountpoint *janus_streaming_create_file_source(
78607864
if(!strstr(filename, ".alaw") && !strstr(filename, ".mulaw")) {
78617865
JANUS_LOG(LOG_ERR, "Can't add 'file' stream, unsupported format (we only support raw mu-Law and a-Law files right now)\n");
78627866
#endif
7863-
janus_mutex_lock(&mountpoints_mutex);
7864-
g_hash_table_remove(mountpoints_temp, &id);
7865-
janus_mutex_unlock(&mountpoints_mutex);
78667867
return NULL;
78677868
}
78687869
janus_audiocodec audio_codec = janus_audiocodec_from_name(acodec);
78697870
#ifdef HAVE_LIBOGG
78707871
if(strstr(filename, ".opus") && audio_codec != JANUS_AUDIOCODEC_OPUS) {
78717872
JANUS_LOG(LOG_ERR, "Can't add 'file' stream, opus file is not associated with an opus rtpmap\n");
7872-
janus_mutex_lock(&mountpoints_mutex);
7873-
g_hash_table_remove(mountpoints_temp, &id);
7874-
janus_mutex_unlock(&mountpoints_mutex);
78757873
return NULL;
78767874
}
78777875
#endif
@@ -8909,18 +8907,12 @@ janus_streaming_mountpoint *janus_streaming_create_rtsp_source(
89098907
/* Now connect to the RTSP server */
89108908
if(janus_streaming_rtsp_connect_to_server(live_rtsp) < 0) {
89118909
/* Error connecting, get rid of the mountpoint */
8912-
janus_mutex_lock(&mountpoints_mutex);
8913-
g_hash_table_remove(mountpoints_temp, &id);
8914-
janus_mutex_unlock(&mountpoints_mutex);
89158910
janus_refcount_decrease(&live_rtsp->ref);
89168911
return NULL;
89178912
}
89188913
/* Send an RTSP PLAY, now */
89198914
if(janus_streaming_rtsp_play(live_rtsp_source) < 0) {
89208915
/* Error trying to play, get rid of the mountpoint */
8921-
janus_mutex_lock(&mountpoints_mutex);
8922-
g_hash_table_remove(mountpoints_temp, &id);
8923-
janus_mutex_unlock(&mountpoints_mutex);
89248916
janus_refcount_decrease(&live_rtsp->ref);
89258917
return NULL;
89268918
}
@@ -8952,9 +8944,6 @@ janus_streaming_mountpoint *janus_streaming_create_rtsp_source(
89528944
janus_refcount_decrease(&helper->ref);
89538945
/* This extra unref is for the init */
89548946
janus_refcount_decrease(&helper->ref);
8955-
janus_mutex_lock(&mountpoints_mutex);
8956-
g_hash_table_remove(mountpoints_temp, &id);
8957-
janus_mutex_unlock(&mountpoints_mutex);
89588947
janus_refcount_decrease(&live_rtsp->ref);
89598948
return NULL;
89608949
}
@@ -8970,9 +8959,6 @@ janus_streaming_mountpoint *janus_streaming_create_rtsp_source(
89708959
JANUS_LOG(LOG_ERR, "Got error %d (%s) trying to launch the RTSP thread...\n",
89718960
error->code, error->message ? error->message : "??");
89728961
g_error_free(error);
8973-
janus_mutex_lock(&mountpoints_mutex);
8974-
g_hash_table_remove(mountpoints_temp, &id);
8975-
janus_mutex_unlock(&mountpoints_mutex);
89768962
janus_refcount_decrease(&live_rtsp->ref); /* This is for the failed thread */
89778963
janus_refcount_decrease(&live_rtsp->ref);
89788964
return NULL;

0 commit comments

Comments
 (0)