Skip to content

Instantly share code, notes, and snippets.

@jzawodn
Created June 14, 2013 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzawodn/5784173 to your computer and use it in GitHub Desktop.
Save jzawodn/5784173 to your computer and use it in GitHub Desktop.
Demonstrate the leak in DBD::mysql that I noticed. If you fail to connect (down host), the program will leak memory. If you're connecting to a server that's up, there is no leak.
#!/usr/bin/perl -w
use strict;
use warnings;
use feature qw(say);
use DBD::mysql;
my $host = 'dev4h';
my $port = 9307;
my $dsn = "DBI:mysql:host=$host;port=$port";
my $user = 'foo';
my $pass = 'bar';
while (1) {
my $dbh = DBI->connect($dsn, $user, $pass);
if ($dbh) {
say "connected to $host:$port";
} else {
say "connect fail to $host:$port: $@";
}
}
exit;
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment