Fix several possible memory leaks.
The color of cursor should not been reset after changing the color of foreground color. close #29.