Correcting variable value assignments and setting allocated memory to null