System keyboard memory leak

a redo of the previous memory leak fix, for easy merging.