Subject: | $sth->execute( undef ) causes "Bad free() ignored (PERL_CORE)" |
If $sth->execute is called with undef for placeholder value, statement deallocation (when $sth goes out of scope, for example) causes "Bad free() ignored (PERL_CORE)". It may require several execute() calls to happen, but then it will be displayed after each call to execute with undef values. Here is simplified code:
----
use DBI;
my $dbh = DBI->connect( 'dbi:Pg:dbname=test', 'test', '', { AutoCommit => 1 } );
for( my $i = 0; $i < 100; $i++ )
{
print STDERR "$i\n";
bug();
}
$dbh->disconnect;
exit;
sub bug
{
my $sth = $dbh->prepare( q{SELECT name FROM t WHERE id IN (?, ?)} );
$sth->execute( undef, undef );
}
-----
The problem is in dbdimp.c line 860:
phs->quoted = strdup("NULL");
When safefree(phs_tpl->quoted) in called later in line 1147, "Bad free() ignored" warning appears because strdup doesn't use perl's safemalloc.
I have created simple patch for this problem.
diff -ru DBD-Pg-1.31.old/dbdimp.c DBD-Pg-1.31/dbdimp.c
--- DBD-Pg-1.31.old/dbdimp.c Mon Oct 27 19:57:02 2003
+++ DBD-Pg-1.31/dbdimp.c Thu Dec 4 16:24:33 2003
@@ -857,9 +857,10 @@
if (!SvOK(newvalue)) {
- phs->quoted = strdup("NULL");
+ phs->quoted = safemalloc(sizeof("NULL"));
if (NULL == phs->quoted)
croak("No memory");
+ strcpy(phs->quoted, "NULL");
phs->quoted_len = strlen(phs->quoted);
} else {
value_string = SvPV(newvalue, value_len);