Added watchdog timer for threads

Added potential memory leak fix