Rather than "if (err)", it's best to add a "fail:" label and a "goto finish;" right before it.