check res for null before free