rtos/linux: fix use of memory after it is freed