extra: use a mutex to wrap linenoise calls and make them threadsafe.

Fixes #3921.
extra: stop rl from leaking each line that is read.