Fixed critical buffer overflow
(cherry picked from commit 378bfbe6238c1fe527526655684271987c388875)
Free memory after getting realpath
(cherry picked from commit 29b7d7cc7914236a8c952e317fc39d0df02ee051)