Skip to content

Commit eaf6234

Browse files
author
Georgi Chorbadzhiyski
committed
Prevent crash on exit.
Calling pthread_cancel( NULL ) results in the same crash as calling pthread_join( NULL, ... ) This fixes the following: Start obecli. obecli> set input decklink obecli> set input opts card-idx=0 obecli> probe input Probing device: Decklink card 0. Timeout 20 seconds Detected input streams: Input-stream-id: 0 - Video: RAW 720x576i 25/1fps Input-stream-id: 1 - Audio: PCM 16 channels 48kHz Encoder outputs: Output-stream-id: 0 - Input-stream-id: 0 - Video: AVC Output-stream-id: 1 - Input-stream-id: 1 - Audio: RAW - SDI audio pair: 1 obecli> quit closing obe Program received signal SIGSEGV, Segmentation fault. 0x00007ffff6675be1 in pthread_cancel () from /lib64/libpthread.so.0 (gdb) bt #0 0x00007ffff6675be1 in pthread_cancel () from /lib64/libpthread.so.0 ob-encoder#1 0x00000000004483d1 in obe_close (h=0x1417860) at obe.c:1233 ob-encoder#2 0x000000000044433f in stop_encode (command=command@entry=0x0, child=child@entry=0x0) at obecli.c:1353 ob-encoder#3 0x0000000000446d92 in main (argc=<optimized out>, argv=<optimized out>) at obecli.c:1534
1 parent 5f44c3a commit eaf6234

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

obe.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,13 @@ static int obe_validate_input_params( obe_input_t *input_device )
559559
return 0;
560560
}
561561

562+
static int __pthread_cancel( pthread_t thread )
563+
{
564+
if ( thread )
565+
return pthread_cancel( thread );
566+
return -1;
567+
}
568+
562569
static int __pthread_join( pthread_t thread, void **retval )
563570
{
564571
if ( thread )
@@ -665,7 +672,7 @@ int obe_probe_device( obe_t *h, obe_input_t *input_device, obe_input_program_t *
665672
break;
666673
}
667674

668-
pthread_cancel( thread );
675+
__pthread_cancel( thread );
669676
__pthread_join( thread, &ret_ptr );
670677

671678
cur_devices = h->num_devices;
@@ -1230,7 +1237,7 @@ void obe_close( obe_t *h )
12301237
/* Cancel input thread */
12311238
for( int i = 0; i < h->num_devices; i++ )
12321239
{
1233-
pthread_cancel( h->devices[i]->device_thread );
1240+
__pthread_cancel( h->devices[i]->device_thread );
12341241
__pthread_join( h->devices[i]->device_thread, &ret_ptr );
12351242
}
12361243

@@ -1304,7 +1311,7 @@ void obe_close( obe_t *h )
13041311
pthread_mutex_unlock( &h->outputs[i]->queue.mutex );
13051312
__pthread_join( h->outputs[i]->output_thread, &ret_ptr );
13061313
/* could be blocking on OS so have to cancel thread too */
1307-
pthread_cancel( h->outputs[i]->output_thread );
1314+
__pthread_cancel( h->outputs[i]->output_thread );
13081315
__pthread_join( h->outputs[i]->output_thread, &ret_ptr );
13091316
}
13101317

0 commit comments

Comments
 (0)