Fixed memory leaks and msh_getenv_l returning incorect struct ptr