Bug #20559 Program crashes when using server-side prepare
Submitted: 20 Jun 2006 9:03 Modified: 3 Jan 2007 0:11
Reporter: Steve Hay Email Updates:
Status: Closed Impact on me:
None 
Category:Connectors: DBD::mysql ( Perl ) Severity:S2 (Serious)
Version:3.0006_1 OS:Windows (Windows XP)
Assigned to: Bugs System CPU Architecture:Any

[20 Jun 2006 9:03] Steve Hay
Description:
I've found another problem with the new server side prepare statements in 3.0006_1.

The program below crashes here:

mysql_st_prepare(sv * 0x0195b0a8, imp_sth_st * 0x0183b008, char * 0x01839470, sv * 0x0000002a) line 2311 + 21 bytes
XS_DBD__mysql__st__prepare(cv * 0x0195850c) line 427 + 42 bytes
[...]

If I delete the " FOR UPDATE" from the SELECT statement then it outputs these errors instead:

FREE ERROR BIND!FREE ERROR FBIND!

If I turn off server side prepare then it works fine, with or without the " FOR UPDATE" clause.

How to repeat:
dbi.pl
------
use strict;
use warnings;
use DBI qw(:sql_types);
my $tmp_dbh = DBI->connect(
  'dbi:mysql:database=mysql', 'root', undef,
  { AutoCommit => 1, PrintError => 0, RaiseError => 1 }
);
$tmp_dbh->do('CREATE DATABASE IF NOT EXISTS test');
$tmp_dbh->disconnect();
my $dsn = 'dbi:mysql:database=test;mysql_server_prepare=1';    # Crashes
#my $dsn = 'dbi:mysql:database=test;mysql_emulated_prepare=1'; # OK
my $dbh = DBI->connect(
  $dsn, 'root', undef,
  { AutoCommit => 1, PrintError => 0, RaiseError => 1 }
);
$dbh->do('DROP TABLE IF EXISTS foo');
$dbh->do(qq{CREATE TABLE foo (
  id  INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  num INT
) ENGINE=InnoDB});
$dbh->trace(3, 'dbitrace.txt');
my $sql = 'SELECT num FROM foo WHERE id = ? FOR UPDATE';
my $sth = $dbh->prepare($sql);
$sth->bind_param(1, 1);
$sth->execute();
my $rows = $sth->fetchall_arrayref({});
$sth->finish();
$dbh->disconnect();

Suggested fix:
Wish I had one!
[20 Jun 2006 12:37] MySQL Verification Team
Thank you for the bug report. I installed DBD according the below
instructions (2 weeks ago):

ActivePerl offers a PPM archive of DBD::mysql. All you need to do is typing

  ppm
  install DBI
  install DBD-mysql

and testing against a 5.0 server I was unable to repeat your test case.

Which server version are you using?
[20 Jun 2006 13:01] Steve Hay
I'm running 4.1.14.

What version of DBD-mysql are you running, though?  I'm not familiar with the PPM installation process that you've used, but it might only install the latest *stable* version (3.0006), whereas my bug report is specifically related to the *development* version (3.0006_1) because only that contains the server-side prepare support.

You can determine the version in use by running:
perl -MDBD::mysql -e "print $DBD::mysql::VERSION"
[20 Jun 2006 17:25] MySQL Verification Team
Yes it is a different version. How you installed the version:
3.0006_1?

Thanks in advance.
[21 Jun 2006 7:36] Steve Hay
Well, I'm sure Patrick knows how I installed it, but for your information:

I downloaded DBD-mysql-3.0006_1 from http://search.cpan.org/dist/DBD-mysql/, extracted the archive, and then ran the usual sequence of commands for building a perl module, namely:

perl Makefile.PL
nmake
nmake test
nmake install
[28 Sep 2006 17:22] Patrick Galbraith
Steve,

I have tested this with the latest 3.0007/7_1 on UNIX, and I think it is fixed. I do not have a windows set up yet (will later this week, next week). Could you please see if the latest DBD::mysql fixes this?

Thanks!
[29 Sep 2006 8:14] Steve Hay
Patrick,

I just tried this again on Windows XP (VC++ 6.0) using 3.0007_1 and the program still crashes, I'm afraid.

I'm running perl 5.8.8 and mysql 4.1.14.
[19 Oct 2006 9:03] Steve Hay
Hi Patrick,

I've just tried this again with 3.0008_1 and it is now a little better, although still not fixed.

The program no longer crashes, but still outputs:

FREE ERROR BIND!FREE ERROR  FBIND!

when run with server-side prepare switched on.  (When it is switched off these errors do not appear.)

I also find that the "stable" version, 3.0008, behaves in the same way.

Steve
[19 Oct 2006 11:40] Patrick Galbraith
Steve,

This is still on win xp?

Thanks!

Patrick
[19 Oct 2006 11:51] Steve Hay
Yes, still XP SP2, all built using VC++ 6.0.

Steve
[26 Oct 2006 10:41] Sveta Smirnova
There is similar bug #23467
[8 Nov 2006 22:03] Gustavo Delfino
I just want to report that I am having the same problem:

FREE ERROR BIND!FREE ERROR  FBIND!FREE ERROR BIND!FREE ERROR  FBIND!

I am using DBD::mysql 3.0008, DBI 1.53, perl 5.8.8 and mysql 5.0.24-standard

Regards,

Gustavo Delfino

perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.9-42.0.3.elsmp, archname=i686-linux
    uname='linux **removed** 2.6.9-42.0.3.elsmp #1 smp fri oct 6 06:21:39 cdt 2006 i686 i686 i386 gnulinux '
    config_args='-de'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.4.6 20060404 (Red Hat 3.4.6-3)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.4.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl): 
  Compile-time options: PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO
  Built under linux
  Compiled at Nov  5 2006 16:43:26
  @INC:
    /usr/local/lib/perl5/5.8.8/i686-linux
    /usr/local/lib/perl5/5.8.8
    /usr/local/lib/perl5/site_perl/5.8.8/i686-linux
    /usr/local/lib/perl5/site_perl/5.8.8
    /usr/local/lib/perl5/site_perl
    .
[9 Nov 2006 11:26] Sergey Perminov
I had the same problem with dev-perl/DBD-mysql 3.0002_p4
After upgrade to 3.0008 version problem dissapeared.
[9 Nov 2006 11:40] Steve Hay
In reply to Sergey Perminov's comment: upgrading to 3.0008 is bound to "fix" the problem, because as stated in my original report, the problem only occurs when using the new server-side prepare feature, which is only in the development versions, e.g. 3.0008_1. The stable versions (e.g. 3.0008) only have the old emulated prepare feature which didn't have the bug to start with.

I still experience the FREE ERROR [F]BIND warnings, albeit without a crash anymore, when using 3.0008_1.
[3 Jan 2007 0:11] Jim Winstead
The "FREE BIND" (and similar) error messages will no longer show up in the DBD::mysql development tree, because the duplicate freeing of bind data has been fixed. This will be included in the next release (probably 4.001).

Thanks for the bug report.
[3 Jan 2007 1:22] Patrick Galbraith
Actually, this should be fixed in the current 4.00 version. Ranger fixed the problem with the fbind structure, and I had fixed the crash (which I found when using DBD::mysql with mod_perl) in 3.0008, and removed the 'FREE BIND' error messages which still were occurring even when there was no problem.
[6 Feb 2007 16:11] Dennis Birkholz
I have the same problem getting a lot of "FREE ERROR BIND!FREE ERROR FBIND!" with the DBD-mysql-driver using the version 4.00.1 on gentoo-linux. (I use the MySQL-backend for the bayes-spam-filter in SpamAssassin)