Fixed memory leak: possible access to out-of-range