pkg/tar: fixing possible nil pointer dereference

If os.OpenFile(...) returns err != nil, f will be nil. So f.Close() would cause a "nil pointer dereference".

Also closing dir.