Fixed "Read from pointer after free" error from coverity report.