Fix segfault in SDBM_File when the destructor is called multiple times
Rafael Garcia-Suarez [Wed, 24 May 2006 13:34:45 +0000 (13:34 +0000)]
p4raw-id: //depot/perl@28298

ext/SDBM_File/SDBM_File.pm
ext/SDBM_File/SDBM_File.xs

index 07a05e1..d1209e0 100644 (file)
@@ -7,7 +7,7 @@ require Tie::Hash;
 use XSLoader ();
 
 our @ISA = qw(Tie::Hash);
-our $VERSION = "1.05";
+our $VERSION = "1.06";
 
 XSLoader::load 'SDBM_File', $VERSION;
 
index 24b2b83..6aafb6b 100644 (file)
@@ -53,16 +53,18 @@ void
 sdbm_DESTROY(db)
        SDBM_File       db
        CODE:
-         sdbm_close(db->dbp);
-         if (db->filter_fetch_key)
-           SvREFCNT_dec(db->filter_fetch_key) ;
-         if (db->filter_store_key)
-           SvREFCNT_dec(db->filter_store_key) ;
-         if (db->filter_fetch_value)
-           SvREFCNT_dec(db->filter_fetch_value) ;
-         if (db->filter_store_value)
-           SvREFCNT_dec(db->filter_store_value) ;
-         safefree(db) ;
+       if (db) {
+           sdbm_close(db->dbp);
+           if (db->filter_fetch_key)
+               SvREFCNT_dec(db->filter_fetch_key) ;
+           if (db->filter_store_key)
+               SvREFCNT_dec(db->filter_store_key) ;
+           if (db->filter_fetch_value)
+               SvREFCNT_dec(db->filter_fetch_value) ;
+           if (db->filter_store_value)
+               SvREFCNT_dec(db->filter_store_value) ;
+           safefree(db) ;
+       }
 
 datum_value
 sdbm_FETCH(db, key)