Fixed access violations

When referencing a pointer, use a pointer variable so that it won't be
automatically destroyed after it goes out of scope.