The reason why freeing was not done yet is because the pointer in these
variables may be:
- Static data set by the readline/libedit library initially, not heap
data.
- Data set by another thread. Although the libraries appear to be not
thread-safe anyway.
To solve this, introduce some TLS variables to hold a pointer for us
when we override the settings, such that we can free them and are
certain they are allocated by us.
Closes GH-20794.