]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 192531 - Bugzilla not properly closing DB statement handles
authorbbaetz%acm.org <>
Fri, 14 Feb 2003 18:37:38 +0000 (18:37 +0000)
committerbbaetz%acm.org <>
Fri, 14 Feb 2003 18:37:38 +0000 (18:37 +0000)
Change code to work arround a perl < 5.8 leak when localising the tied
statement attributes. Also, clear the sql statestack compat stuff so that
the handles are really dead by the time we disconnect

r,a=justdave

Bugzilla.pm
Bugzilla/DB.pm

index 56d1f24cc7c4e4ed369112333cfc5cfae2711ee1..366acb163923ed2ad9fdfd42fe32c6873100d2ca 100644 (file)
@@ -94,6 +94,17 @@ sub switch_to_main_db {
 sub _cleanup {
     undef $_cgi;
 
+    # See bug 192531. If we don't clear the possibly active statement handles,
+    # then when this is called from the END block, it happens _before_ the
+    # destructors in Bugzilla::DB have happened.
+    # See http://rt.perl.org/rt2/Ticket/Display.html?id=17450#38810
+    # Without disconnecting explicitly here, noone notices, because DBI::END
+    # ends up calling DBD::mysql's $drh->disconnect_all, which is a noop.
+    # This code is evil, but it needs to be done, at least until SendSQL and
+    # friends can be removed
+    @Bugzilla::DB::SQLStateStack = ();
+    undef $Bugzilla::DB::_current_sth;
+
     # When we support transactions, need to ->rollback here
     $_dbh_main->disconnect if $_dbh_main;
     $_dbh_shadow->disconnect if $_dbh_shadow and Param("shadowdb");
index 23078369adeea93dc233f87137923b2559fa0529..0de9b612c525d3ebd4bb455fa5854b61f46e9c56 100644 (file)
@@ -54,13 +54,21 @@ sub ConnectToDatabase {
 }
 
 # XXX - mod_perl
-my $_current_sth;
+# These use |our| instead of |my| because they need to be cleared from
+# Bugzilla.pm. See bug 192531 for details.
+our $_current_sth;
+our @SQLStateStack = ();
 sub SendSQL {
     my ($str) = @_;
 
     require Bugzilla;
 
     $_current_sth = Bugzilla->dbh->prepare($str);
+
+    # This is really really ugly, but its what we get for not doing
+    # error checking for 5 years. See bug 189446 and bug 192531
+    $_current_sth->{RaiseError} = 0;
+
     return $_current_sth->execute;
 }
 
@@ -98,12 +106,7 @@ sub FetchSQLData {
         return @result;
     }
 
-    # This is really really ugly, but its what we get for not doing
-    # error checking for 5 years. See bug 189446.
-    {
-        local $_current_sth->{RaiseError};
-        return $_current_sth->fetchrow_array;
-    }
+    return $_current_sth->fetchrow_array;
 }
 
 sub FetchOneColumn {
@@ -111,9 +114,6 @@ sub FetchOneColumn {
     return $row[0];
 }
 
-# XXX - mod_perl
-my @SQLStateStack = ();
-
 sub PushGlobalSQLState() {
     push @SQLStateStack, $_current_sth;
     push @SQLStateStack, $_fetchahead;