From 459ebc8397b8cb13a67ebb4cb0b7aa941fbfbf29 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 11 Nov 2015 14:47:50 +0100 Subject: libtests/termios04: Avoid use of freed memory --- .../libtests/termios04/termios_testdriver_intr.c | 42 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/testsuites/libtests/termios04/termios_testdriver_intr.c b/testsuites/libtests/termios04/termios_testdriver_intr.c index 94ebe28629..53764fb9da 100644 --- a/testsuites/libtests/termios04/termios_testdriver_intr.c +++ b/testsuites/libtests/termios04/termios_testdriver_intr.c @@ -181,8 +181,6 @@ rtems_device_driver termios_test_driver_initialize( void *arg ) { - rtems_status_code status; - rtems_termios_initialize(); /* @@ -190,15 +188,45 @@ rtems_device_driver termios_test_driver_initialize( */ (void) rtems_io_register_name( TERMIOS_TEST_DRIVER_DEVICE_NAME, major, 0 ); + return RTEMS_SUCCESSFUL; +} + +static int first_open(int major, int minor, void *arg) +{ + rtems_status_code status; + status = rtems_timer_create(rtems_build_name('T', 'M', 'R', 'X'), &Rx_Timer); - if ( status ) + if ( status != RTEMS_SUCCESSFUL ) rtems_fatal_error_occurred(1); status = rtems_timer_create(rtems_build_name('T', 'M', 'T', 'X'), &Tx_Timer); - if ( status ) + if ( status != RTEMS_SUCCESSFUL ) rtems_fatal_error_occurred(1); - return RTEMS_SUCCESSFUL; + return 0; +} + +static int last_close(int major, int minor, void *arg) +{ + rtems_status_code status; + + status = rtems_timer_cancel(Rx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + status = rtems_timer_cancel(Tx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + status = rtems_timer_delete(Rx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + status = rtems_timer_delete(Tx_Timer); + if ( status != RTEMS_SUCCESSFUL ) + rtems_fatal_error_occurred(1); + + return 0; } rtems_device_driver termios_test_driver_open( @@ -210,8 +238,8 @@ rtems_device_driver termios_test_driver_open( rtems_status_code sc; rtems_libio_open_close_args_t *args = arg; static const rtems_termios_callbacks Callbacks = { - NULL, /* firstOpen */ - NULL, /* lastClose */ + first_open, /* firstOpen */ + last_close, /* lastClose */ #if defined(TASK_DRIVEN) termios_test_driver_inbyte_nonblocking,/* pollRead */ #else -- cgit v1.2.3