Bad, vile and meaningless: DB2 bug from Alan's clob

DBD::DB2 V0.76 has a memory leak

The problem is duplicate set of NUM_OF_FIELDS $sth property. In the code, the field value is first initialised to 0, and then set to appropriate value using a different method, with a SViv. This duplicate setting of the field makes $sth refcounting fail, and thus you

The fix is to directly set the correct number value with the appropriate macro, and remove the whole SViv.

How to determine if you are affected

Try executing some code along the lines of following:

my $dbh = DBI->connect($dsn, $user, $password, {
    RaiseError => 1
for (1..1000) {
    $dbh->prepare('VALUES IDENTITY_VAL_LOCAL()'); # or any SQL statement

Fire up a top, and watch your memory dwindle, if you are bitten.

In case you can't patch the binary, consider using prepare_cached which will cache handles by their text. This helps if you make use of placeholders, so that the total amount of queries you need prepared is small.