1
- /* $OpenBSD: bio_chain.c,v 1.15 2023/03/04 12:13:11 tb Exp $ */
1
+ /* $OpenBSD: bio_chain.c,v 1.16 2023/08/07 11:00:54 tb Exp $ */
2
2
/*
3
3
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
4
4
*
@@ -460,6 +460,47 @@ bio_set_next_link_test(void)
460
460
return link_chains (use_bio_push );
461
461
}
462
462
463
+ static long
464
+ dup_leak_cb (BIO * bio , int cmd , const char * argp , int argi , long argl , long ret )
465
+ {
466
+ if (argi == BIO_CTRL_DUP )
467
+ return 0 ;
468
+
469
+ return ret ;
470
+ }
471
+
472
+ static int
473
+ bio_dup_chain_leak (void )
474
+ {
475
+ BIO * bio [CHAIN_POP_LEN ];
476
+ BIO * dup ;
477
+ int failed = 1 ;
478
+
479
+ if (!bio_chain_create (BIO_s_null (), bio , nitems (bio )))
480
+ goto err ;
481
+
482
+ if ((dup = BIO_dup_chain (bio [0 ])) == NULL ) {
483
+ fprintf (stderr , "BIO_set_callback() failed\n" );
484
+ goto err ;
485
+ }
486
+
487
+ BIO_set_callback (bio [CHAIN_POP_LEN - 1 ], dup_leak_cb );
488
+
489
+ BIO_free_all (dup );
490
+ if ((dup = BIO_dup_chain (bio [0 ])) != NULL ) {
491
+ fprintf (stderr , "BIO_dup_chain() succeeded unexpectedly\n" );
492
+ BIO_free_all (dup );
493
+ goto err ;
494
+ }
495
+
496
+ failed = 0 ;
497
+
498
+ err :
499
+ bio_chain_destroy (bio , nitems (bio ));
500
+
501
+ return failed ;
502
+ }
503
+
463
504
int
464
505
main (int argc , char * * argv )
465
506
{
@@ -468,6 +509,7 @@ main(int argc, char **argv)
468
509
failed |= bio_chain_pop_test ();
469
510
failed |= bio_push_link_test ();
470
511
failed |= bio_set_next_link_test ();
512
+ failed |= bio_dup_chain_leak ();
471
513
472
514
return failed ;
473
515
}
0 commit comments