Pass exitCode by reference

Arguments to defer statements are evaluated when the defer statement is
evaluated, so pass exitCode by reference instead.

Fixes issue #346