Make sure that we have a valid object before calling close!
Make sure that we have a valid object before calling close!

This fixes [#2171](https://github.com/opscode/chef/issues/2171) when a
tempfile cannot be created or proper filesystem permissions do not
exist. This allows the proper exception to be thrown.

tas50/chef-1,jkerry/chef,robmul/chef,oclaussen/chef,higanworks/chef,youngjl1/chef,ranjib/chef,ranjib/chef,nvwls/chef,aaron-lane/chef,Tensibai/chef,ChaosCloud/chef,brettcave/chef,Tensibai/chef,ChaosCloud/chef,gene1wood/chef,strangelittlemonkey/chef,docwhat/chef,jonlives/chef,strangelittlemonkey/chef,evan2645/chef,mikedodge04/chef,criteo-forks/chef,webframp/chef,sanditiffin/chef,juliandunn/chef,oclaussen/chef,criteo-forks/chef,mikedodge04/chef,webframp/chef,higanworks/chef,natewalck/chef,b002368/chef-repo,nathwill/chef,Tensibai/chef,MsysTechnologiesllc/chef,higanworks/chef,josb/chef,gene1wood/chef,tbunnyman/chef,jonlives/chef,jonlives/chef,mikedodge04/chef,onlyhavecans/chef,sekrett/chef,b002368/chef-repo,evan2645/chef,natewalck/chef,martinisoft/chef,mal/chef,evan2645/chef,youngjl1/chef,webframp/chef,brettcave/chef,sekrett/chef,mwrock/chef,nathwill/chef,3dinfluence/chef,docwhat/chef,Tensibai/chef,3dinfluence/chef,tbunnyman/chef,evan2645/chef,onlyhavecans/chef,jkerry/chef,docwhat/chef,mikedodge04/chef,robmul/chef,jaymzh/chef,mwrock/chef,josb/chef,b002368/chef-repo,strangelittlemonkey/chef,gene1wood/chef,sekrett/chef,mal/chef,aaron-lane/chef,tomdoherty/chef,tbunnyman/chef,jonlives/chef,onlyhavecans/chef,nvwls/chef,juliandunn/chef,chef/chef,robmul/chef,Kast0rTr0y/chef,mattray/chef,brettcave/chef,nathwill/chef,Kast0rTr0y/chef,aaron-lane/chef,MsysTechnologiesllc/chef,someara/chef,jaymzh/chef,someara/chef,mikedodge04/chef,ChaosCloud/chef,ranjib/chef,strangelittlemonkey/chef,ranjib/chef,youngjl1/chef,b002368/chef-repo,criteo-forks/chef,tomdoherty/chef,onlyhavecans/chef,criteo-forks/chef,jonlives/chef,oclaussen/chef,natewalck/chef,webframp/chef,tas50/chef-1,tomdoherty/chef,docwhat/chef,chef/chef,MsysTechnologiesllc/chef,youngjl1/chef,natewalck/chef,juliandunn/chef,Kast0rTr0y/chef,nvwls/chef,3dinfluence/chef,higanworks/chef,josb/chef,oclaussen/chef,mwrock/chef,brettcave/chef,docwhat/chef,docwhat/chef,youngjl1/chef,youngjl1/chef,mikedodge04/chef,Ppjet6/chef,MsysTechnologiesllc/chef,tomdoherty/chef,jkerry/chef,tas50/chef-1,webframp/chef,juliandunn/chef,onlyhavecans/chef,evan2645/chef,ranjib/chef,onlyhavecans/chef,robmul/chef,sanditiffin/chef,Ppjet6/chef,ranjib/chef,Kast0rTr0y/chef,Ppjet6/chef,robmul/chef,juliandunn/chef,Tensibai/chef,jaymzh/chef,nvwls/chef,chef/chef,josb/chef,Kast0rTr0y/chef,nvwls/chef,nathwill/chef,Ppjet6/chef,gene1wood/chef,mal/chef,mal/chef,someara/chef,higanworks/chef,tbunnyman/chef,jkerry/chef,sanditiffin/chef,mal/chef,someara/chef,b002368/chef-repo,sekrett/chef,jonlives/chef,tbunnyman/chef,sekrett/chef,Ppjet6/chef,mattray/chef,nathwill/chef,chef/chef,jkerry/chef,sanditiffin/chef,b002368/chef-repo,tomdoherty/chef,tas50/chef-1,aaron-lane/chef,aaron-lane/chef,natewalck/chef,ChaosCloud/chef,nathwill/chef,jaymzh/chef,3dinfluence/chef,martinisoft/chef,martinisoft/chef,sanditiffin/chef,martinisoft/chef,tbunnyman/chef,criteo-forks/chef,mwrock/chef,jkerry/chef,oclaussen/chef,oclaussen/chef,martinisoft/chef,mattray/chef,criteo-forks/chef,sanditiffin/chef,brettcave/chef,3dinfluence/chef,someara/chef,ChaosCloud/chef,aaron-lane/chef,josb/chef,3dinfluence/chef,mal/chef,brettcave/chef,mattray/chef,strangelittlemonkey/chef,ChaosCloud/chef,mattray/chef,Kast0rTr0y/chef,evan2645/chef,someara/chef,robmul/chef,natewalck/chef,sekrett/chef,Ppjet6/chef,josb/chef,strangelittlemonkey/chef,webframp/chef,nvwls/chef