From d2df76a89f29acd03383da6a76839435c51e8621 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 18 Sep 2014 14:34:50 +0000 Subject: cleanup database handle diff --git a/lib/rddb.pm b/lib/rddb.pm index 1ef296c..a7506a2 100755 --- a/lib/rddb.pm +++ b/lib/rddb.pm @@ -24,12 +24,18 @@ sub opendb return ($dbh, 'OK', 'success'); } +sub closedb +{ + my $dbh = shift; + $dbh->disconnect(); +} + sub get_token { my $username = shift; my ($dbh, $state, $errorstring) = opendb(); - unless($dbh) { + unless(defined $dbh) { return ('', $state, $errorstring); } @@ -40,9 +46,13 @@ sub get_token or return ('', 'ERROR', "Database Error: " . $sth->errstr); my ($token) = $sth->fetchrow_array; - return ($token, 'OK', 'success') if(defined $token); + $sth->finish(); + closedb($dbh); - return ('', 'ERROR', "user '" . $username . "' not known by rivendell") + unless(defined $token) { + return ('', 'ERROR', "user '" . $username . "' not known by rivendell") + } + return ($token, 'OK', 'success'); } return 1; -- cgit v0.10.2