Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DB_File CPAN distribution.

Report information
The Basics
Id:
89589
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
vitaliy.tokarev [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
Critical
Broken in:
1.829
Fixed in:
1.830



Subject: Memory leaks when failed to open db
Hello, I have attached a patch which prevents memory leakage when tie(..., $DB_HASH) fails. Test code: #!/usr/bin/perl use strict; use warnings; use DB_File; use Fcntl qw(:DEFAULT :mode); sub DEFAULT_MODE { S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH } my $count = 500_000; # set as you wish my %hash; my $file = '/etc/sasl2/sasldb_not_exists'; # set invalid destination while ($count > 0) { tie (%hash, 'DB_File', $file, O_RDWR | O_CREAT, DEFAULT_MODE, $DB_HASH); $count--; $count % 1000 or sleep(1); # slowmo :) } Thanks.
Subject: DB_File_01.diff
--- DB_File.xs.orig 2013-10-17 16:44:45.508895581 +0400 +++ DB_File.xs 2013-10-17 16:46:03.538588908 +0400 @@ -1494,10 +1494,10 @@ status = (RETVAL->dbp->cursor)(RETVAL->dbp, NULL, &RETVAL->cursor, 0) ; /* printf("cursor returned %d %s\n", status, db_strerror(status)) ; */ - } - - if (status) - RETVAL->dbp = NULL ; + } else { + db_close(RETVAL); // close **dbp handle to prevent mem.leak + RETVAL->dbp = NULL ; + } }
Many thanks for the patch. Even better that you included a script that reproduces the issue. Applied to my dev copy. Will try to get it uploaded to CPAN when I get cheers Paul
From: vitaliy.tokarev@gmail.com
Hello, Sorry, for long repsonse.
Show quoted text
> Many thanks for the patch. Even better that you included a script that > reproduces the issue.
There are no _easy_ way to reproduce this bug within perl script. As you know, Perl does not have possibility to control anything outside itself, i.e. everything that happens inside XS is a black box for the Perl. The one of the many ways to catch memory leakage is using valgrind tool. Also, in the documentation and samples for bdb 2+ describes after each db_create() call is using db_close(). API reference to db_create: http://docs.oracle.com/cd/E17076_03/html/api_reference/C/frame_main.html Closing Databases: http://docs.oracle.com/cd/E17076_03/html/gsg/C/coredbclose.html Database Example (describes virtual functions): http://docs.oracle.com/cd/E17076_03/html/gsg/C/CoreDbUsage.html Database Usage Example (uses functions from link above): http://docs.oracle.com/cd/E17076_03/html/gsg/C/DbUsage.html P.S. Thanks for patched version 1.830!


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.