htsp: fixed wrong mutex usage and leaks in htsp_write_scheduler()