Fix memory corruption when using pkg files.