Subject: | failure to clean up in CGI::Session:Driver::DBI routines |
Date: | Wed, 20 May 2009 21:50:49 -0700 (PDT) |
To: | bug-CGI-Session [...] rt.cpan.org |
From: | eponymous alias <eponymousalias [...] yahoo.com> |
The CGI-Session-4.00_08/Session/Driver/DBI.pm routines do not
properly close out their statement handles before returning.
This results in resources needlessly held for the duration of
the session, and in error messages when the database handle
is ultimately closed. For instance, the code needs the
following change:
--- DBI.pm.orig Fri Feb 11 00:18:27 2005
+++ DBI.pm Wed May 20 21:35:27 2009
@@ -57,6 +57,7 @@
$sth->execute( $sid ) or return $self->set_error( "retrieve(): \$sth->execute failed with error message " . $dbh->errstr);
my ($row) = $sth->fetchrow_array();
+ $sth->finish;
return 0 unless $row;
return $row;
}
As an example of what the present construction causes, we see
the following message continually in the Apache error logs:
DBI::db=HASH(0x2439990)->disconnect invalidates 1 active
statement handle (either destroy statement handles or
call finish on them before disconnecting)
due to the particular missing cleanup noted above.
That kind of fix (adding $sth->finish; calls) applies not just
to the retrieve routine, but also to most other routines in
the DBI.pm file. Every time a local statement handle is
created in such a routine, it should be destroyed with a
$sth->finish; call before the routine is exited, no matter
what code path is followed.