Fix socket close after work

example:

#!/usr/bin/env perl
use AnyEvent;
use AnyEvent::Ping;

my @results;
my @a  = ('127.0.0.1');

for my $iter (1 .. 10) {
  my @copy = @a;
  my $cv = AnyEvent->condvar;
  my $ping = AnyEvent::Ping->new;
  $ping->timeout(0.1);
  while (@copy) {
    my $url = shift @copy;
    $cv->begin;
    $ping->ping(
      $url, 1,
      sub {
        push @results, [$url, $_[0]->[0][0], $_[0]->[0][1]];
        $cv->end;
        $ping->end if scalar @copy == 0; # comment line and it's broken with
        # Unable to create icmp socket : Too many open files
      }
     );
  }
  $cv->recv;
}