handle malloc() failure in encoding setup code
minor code cleanup
make encoding setup code safer by not expecting sys.getdefaultencoding() to safely return a bytes object
free sys module reference earlier in encoding setup code