Serial event fix and resource leakage fixes

* Fixes issue #1340, CPU usage now down to less than 1% on my machine (from around 15% before)
* Fixes various resource leaks found in serial, parallel and smartcard channel.
* Fixes various bugs in the serial redirection implementation.

Currently there is one issue left, opening a terminal will abort every second time when a character is received with a read error.