Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 83051
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: CAPTTOFU [...] cpan.org
Requestors: vasek.balcar [...] spolecne.cz
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: 4.033_03



Subject: Access to $sth->{ParamValues} leaks
Seems like library returns the wrong refcount? Forget to release pvhv? if (strEQ(key, "ParamValues")) { HV *pvhv= newHV(); if (DBIc_NUM_PARAMS(imp_sth)) { int n; char key[100]; I32 keylen; for (n= 0; n < DBIc_NUM_PARAMS(imp_sth); n++) { keylen= sprintf(key, "%d", n); hv_store(pvhv, key, keylen, newSVsv(imp_sth->params[n].value), 0); } } retsv= newRV_noinc((SV*)pvhv); }
Subject: test-leaky-mysql.pl
#!/usr/bin/perl -w use strict; use DBI; use Data::Dumper; # CREATE DATABASE test; # USE test; # CREATE TABLE `employee` ( # `id` int(11) unsigned NOT NULL AUTO_INCREMENT, # PRIMARY KEY (`id`) # ) ENGINE=InnoDB DEFAULT CHARSET=latin1; my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost","root",undef); my $sth = $dbh->prepare("SELECT * FROM employee WHERE id = ?"); while (1) { $sth->execute('123456789'); my $row = $sth->fetchrow_hashref(); print Data::Dumper->Dump([$sth->{ParamValues}]); $sth->finish(); }
On Wed Jan 30 11:03:09 2013, VASEK wrote: Show quoted text
> Seems like library returns the wrong refcount? Forget to release pvhv? > > if (strEQ(key, "ParamValues")) > { > HV *pvhv= newHV(); > if (DBIc_NUM_PARAMS(imp_sth)) > { > int n; > char key[100]; > I32 keylen; > for (n= 0; n < DBIc_NUM_PARAMS(imp_sth); n++) > { > keylen= sprintf(key, "%d", n); > hv_store(pvhv, key, > keylen, newSVsv(imp_sth->params[n].value), 0); > } > } > retsv= newRV_noinc((SV*)pvhv); > }
I confirm the issue. It seems to be enough to "mortilize" the return value, i.e. do "retsv= sv_2mortal(newRV_noinc((SV*)pvhv))".
Subject: [rt.cpan.org #83051]
Date: Thu, 18 Apr 2013 18:00:58 +0300
To: bug-DBD-mysql [...] rt.cpan.org
From: Alexander Kubrack <kubrack [...] gmail.com>
I confirm it too, and used the patch listed below for fix it locally. --- /usr/ports/databases/p5-DBD-mysql/work/DBD-mysql-4.021/dbdimp.c 2012-04-28 16:48:56.000000000 +0300 +++ dbdimp.c 2013-04-18 17:03:53.000000000 +0300 @@ -4441,7 +4441,7 @@ keylen, newSVsv(imp_sth->params[n].value), 0); } } - retsv= newRV_noinc((SV*)pvhv); + retsv= sv_2mortal(newRV_noinc((SV*)pvhv)); } break; case 'S':
RT-Send-CC: CAPTTOFU [...] cpan.org
Can you please look at this one?
Hi Patrick, We have just "celebrated" 2nd year from the last activity about this bug and it still seems to be unfixed, despite the proposed patch in this TT seems to fix the leak ... Please, any chance you can take a look? Anything I can help with? -- vasek
On Mon Oct 12 08:51:31 2015, VASEK wrote: Show quoted text
> > We have just "celebrated" 2nd year from the last activity about this > bug and it still seems to be unfixed, despite the proposed patch in > this TT seems to fix the leak ... > > Please, any chance you can take a look? Anything I can help with?
Thanks for pinging the bug report. I just applied the patch to DBD::mysql here: https://github.com/perl5-dbi/DBD-mysql/commit/7a09e8a8c7162fdbb4a043602f4e0f81c2f7c5aa If you'd like to contribute some code, adding a unit test would be nice :D You can add it here in the RT ticket or send it as a pull request to the above git repo. -- Michiel