The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
.gitignore 045
Bzip2.xs 65
Changes 023
MANIFEST 14
META.json 34
META.yml 1516
Makefile.PL 13
README 940
README.md 0101
SIGNATURE 1215
lib/Compress/Bzip2.pm 5461
t/090-memory-usage.pl 059
t/900_leaktrace.t 031
13 files changed (This is a version diff) 186367
@@ -0,0 +1,45 @@
+/.gdbinit
+*~
+.bash_history
+Bzip2.bs
+Bzip2.c
+Bzip2.o
+Compress-Bzip2-*.tar.gz
+Debian_CPANTS.txt
+MANIFEST.files
+META.yml
+MYMETA.json
+MYMETA.yml
+Makefile
+Makefile.old
+blib/
+bzlib-src/Makefile.old
+const-c.inc
+const-xs.inc
+/log.*
+pm_to_blib
+show_bzversion
+t/011-tmp-sample.bz2
+t/020-tmp-sample.bz2
+t/021-tmp-sample.bz2
+t/022-tmp-sample.bz2
+t/023-tmp-sample.bz2
+t/024-tmp-reference.bz2
+t/024-tmp-sample.bz2
+t/025-tmp-reference.bz2
+t/025-tmp-sample.bz2
+t/026-tmp-reference.bz2
+t/026-tmp-sample.bz2
+t/030-tmp-sample.txt
+t/031-tmp-sample.txt
+t/032-tmp-sample.txt
+t/033-tmp-sample.txt
+t/034-tmp-reference.bz2
+t/034-tmp-reference.txt
+t/034-tmp-sample.txt
+t/035-tmp-sample.txt
+t/041-tmp-protected.bz2
+t/050-tmp-out.bz2
+t/051-tmp-out.bz2
+t/051-tmp-reference-out-bunzip2.txt
+t/060-tmp-out.txt
@@ -2033,7 +2033,7 @@ MY_bzclose(obj, abandon=0)
 	  XPUSHs(sv_2mortal(newSVpv("",0)));
       }
       else
-        XPUSHs(outbuf);
+        XPUSHs(sv_2mortal(outbuf));
 
       if (GIMME == G_ARRAY) 
         XPUSHs(sv_2mortal(newSViv(global_bzip_errno)));
@@ -2096,7 +2096,7 @@ MY_bzflush(obj, flag=0)
       if (outbuf==NULL)
 	XPUSHs(sv_newmortal());
       else
-	XPUSHs(outbuf);
+	XPUSHs(sv_2mortal(outbuf));
 
       if (GIMME == G_ARRAY) 
 	XPUSHs(sv_2mortal(newSViv(global_bzip_errno)));
@@ -2440,7 +2440,7 @@ MY_bzdeflate(obj, buffer)
 	XPUSHs(sv_2mortal(newSVpv("",0)));
     }
     else
-      XPUSHs(outbuf);
+      XPUSHs(sv_2mortal(outbuf));
 
     if (GIMME == G_ARRAY) 
       XPUSHs(sv_2mortal(newSViv(global_bzip_errno)));
@@ -2479,7 +2479,6 @@ bzinflateInit(...)
 
     perlobj = newSV(0);
     sv_setref_iv( perlobj, "Compress::Bzip2", PTR2IV(obj) );
-    sv_2mortal(perlobj);
 
     for (i=0; i < items; i+=2) {
       param = (char*) SvPV( ST(i), lnparam );
@@ -2487,7 +2486,7 @@ bzinflateInit(...)
       bzfile_setparams( obj, param, setting );
     }
 
-    XPUSHs(perlobj);
+    XPUSHs(sv_2mortal(perlobj));
     if (GIMME == G_ARRAY) 
       XPUSHs(sv_2mortal(newSViv(global_bzip_errno)));
   }
@@ -2547,7 +2546,7 @@ MY_bzinflate(obj, buffer)
 	XPUSHs(sv_2mortal(newSVpv("",0)));
     }
     else
-      XPUSHs(outbuf);
+      XPUSHs(sv_2mortal(outbuf));
 
     if (GIMME == G_ARRAY) 
       XPUSHs(sv_2mortal(newSViv(global_bzip_errno)));
@@ -154,3 +154,26 @@ in a lot of places.
 
 2.17 2013-08-28 rurban
    - Fixed license in README (thanks to John Peacock)
+
+2.18 2014-08-06 rurban
+   - [cpan #68572] add ccdlflags for show_bzversion missing -R also, similar to the
+     fix in 2.11. Not a EUMM bug.
+   - require constant 1.04 (since 5.8) to accept hashrefs.
+   - add META to MANIFEST
+
+2.19 2015-10-24 rurban
+   - fixed generated SIGNATURE (EUMM parallel make issue)
+
+2.20 2015-01-15 rurban
+   - Convert README to markdown, mention the preferred IO::Compress::Bzip2 in
+     the docs (done by Pattarawat Chormai, GH PR #2)
+
+2.21 2015-02-17 rurban
+   - Add leaktrace test
+   - Add .gitignore
+
+2.22 2015-02-17 rurban
+   - Fixed huge decompress memory leak, leaking every single XS outbut buffer.
+   - Better memory leak testcase with Memory::Dump, t/090-memory-usage.pl
+     (RT #102211 by Nick Koston)
+   - clarify docs that deflate = compress, inflate = uncompress
@@ -1,4 +1,5 @@
-README
+.gitignore
+README.md
 Changes
 MANIFEST
 COPYING
@@ -41,6 +42,7 @@ t/071-gzuncomp.t
 t/080-version.t
 t/081-basic.t
 t/082-stream.t
+t/090-memory-usage.pl
 bzlib-src/blocksort.c
 bzlib-src/bz-common.xsl
 bzlib-src/bzdiff
@@ -103,6 +105,7 @@ bzlib-src/xmlproc.sh
 bzlib-src/t/01-baseline.t
 bzlib-src/t/lib.pl
 t/900_kwalitee.t
+t/900_leaktrace.t
 t/900_meta.t
 t/900_perl_minimum_version.t
 t/900_pod-coverage.t
@@ -4,7 +4,7 @@
       "Rob Janes <arjay@cpan.org>"
    ],
    "dynamic_config" : 1,
-   "generated_by" : "ExtUtils::MakeMaker version 6.72, CPAN::Meta::Converter version 2.131560",
+   "generated_by" : "ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.143240",
    "license" : [
       "perl_5"
    ],
@@ -43,7 +43,8 @@
             "File::Copy" : "0",
             "File::Spec" : "0",
             "Getopt::Std" : "0",
-            "Test::More" : "0"
+            "Test::More" : "0",
+            "constant" : "1.04"
          }
       }
    },
@@ -56,5 +57,5 @@
          "url" : "https://github.com/rurban/Compress-Bzip2"
       }
    },
-   "version" : "2.17"
+   "version" : "2.22"
 }
@@ -3,33 +3,34 @@ abstract: 'Interface to Bzip2 compression library'
 author:
   - 'Rob Janes <arjay@cpan.org>'
 build_requires:
-  ExtUtils::MakeMaker: 0
+  ExtUtils::MakeMaker: '0'
 configure_requires:
-  ExtUtils::MakeMaker: 0
+  ExtUtils::MakeMaker: '0'
 dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 6.72, CPAN::Meta::Converter version 2.131560'
+generated_by: 'ExtUtils::MakeMaker version 7.04, CPAN::Meta::Converter version 2.143240'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
-  version: 1.4
+  version: '1.4'
 name: Compress-Bzip2
 no_index:
   directory:
     - t
     - inc
 recommends:
-  Compress::Raw::Bzip2: 2.060
-  Compress::Zlib: 1.19
-  IO::Compress::Bzip2: 2.060
+  Compress::Raw::Bzip2: '2.060'
+  Compress::Zlib: '1.19'
+  IO::Compress::Bzip2: '2.060'
 requires:
-  Carp: 0
-  Config: 0
-  Fcntl: 0
-  File::Copy: 0
-  File::Spec: 0
-  Getopt::Std: 0
-  Test::More: 0
+  Carp: '0'
+  Config: '0'
+  Fcntl: '0'
+  File::Copy: '0'
+  File::Spec: '0'
+  Getopt::Std: '0'
+  Test::More: '0'
+  constant: '1.04'
 resources:
   license: http://dev.perl.org/licenses/
   repository: https://github.com/rurban/Compress-Bzip2
-version: 2.17
+version: '2.22'
@@ -30,6 +30,7 @@ WriteMakefile(
   NAME              => 'Compress::Bzip2',
   VERSION_FROM      => $Bzip2{pm},
   PREREQ_PM         => {
+    'constant'   => 1.04, # for constant => {}
     'Test::More' => 0,
     'File::Spec' => 0,
     'File::Copy' => 0,
@@ -43,7 +44,7 @@ WriteMakefile(
    (ABSTRACT_FROM  => $Bzip2{pm},
     AUTHOR         => 'Rob Janes <arjay@cpan.org>') : ()),
   LIBS             => $BUILD_BZLIB ? [] : [ $BZLIB_LIB ? "-L$BZLIB_LIB -lbz2" : '-lbz2' ],
-  # EUMM bug #84345 missing -R
+  # ccdlflags needed for -R [cpan #68572]
   LDDLFLAGS         => $Config{lddlflags} . " " . $Config{ccdlflags},
   INC               => $BUILD_BZLIB ? '-Ibzlib-src' : $BZLIB_INCLUDE ? "-I$BZLIB_INCLUDE" : '',
   clean             => {
@@ -172,6 +173,7 @@ sub ParseCONFIG {
     my $command = $Config{cc} .
 	' '. $Config{ccflags} .
 	( $BZLIB_INCLUDE ? " -I$BZLIB_INCLUDE" : '' ) .
+	' '. $Config{ccdlflags} .
 	' '. $Config{ldflags} .
 	' -o show_bzversion show_bzversion.c' .
 	( $BZLIB_LIB ? " -L$BZLIB_LIB" : '' ) .
@@ -1,94 +0,0 @@
-
-Compress::Bzip2
-
-Version 2.17
-
-2013-08-28
-
-The subdirectory bzlib-src contains almost all of the files from the
-1.0.6 distribution of bzip2.  What's missing is that I only included
-the html flavour of the documentation.  See the README in there for
-more information.
-
-DESCRIPTION
-===========
-
-This module provides a Perl interface to the bzip2 compression algorithms.
-It uses the low level interface to the algorithm, and reimplements all
-high level routines.
-
-What is Bzip2 ?
-===============
-Bzip2 is a portable lossless data compression library written in ANSI C.
-It offers pretty fast compression and fast decompression.
-Bzip2 has very good results, if you want to compress ASCII Documents.
-
-Bzip2 is probably not great for streaming compression.  It fills it's
-internal buffer, which depending of parameters is between 100k and 900k
-in size, before it outputs ANY compressed data.  It works best compressing
-an entire document.
-
-Streaming decompression on the other hand, gives a steady torrent of bytes.
-
-What is Compress::Bzip2 ?
-====================
-Compress::Bzip2 provided early Bzip2 bindings for Perl5 compatible to
-the old Compress::Zlib library. See Compress::Raw::Bzip2 for the new API
-compatible with IO::Compress.
-
-It's my intent to make this package like the Compress::Zlib package, so
-that code that uses one can fairly easily use the other.  The perlxs stuff
-that's visible to perl has methods that have the same names as their
-Compress::Zlib counterparts, except that the "g" is changed to a "b".
-
-Most code that uses Compress::Zlib should be able to use this package.
-Simply change
-
-   $gz = Compress::Zlib::gzopen( "filename", "w" );
-
-to
-
-   $gz = Compress::Bzip2::gzopen( "filename", "w" );
-
-I made aliases of all the Compress::Zlib functions.  Some of them don't
-return anything useful, like crc32 or adler32, cause bzip2 doesn't
-do that sort of thing.  Take a look at t/070-gzcomp.t and t/071-gzuncomp.t.
-
-Bug fixes and other feedback are welcome.
-
-Copyright
-=========
-bzip2
-Julian Seward, j s e w a r d   a t   a c m . o r g
-
-Compress-Bzip2 prior to 2.0 is distributed under the terms of the
-GNU General Public License (GPL).  See the file COPYING.
-
-Since version 2.0 Compress-Bzip2 is dual-licensed.
-You can redistribute it and/or modify it under the same terms as Perl
-itself, either Perl version 5.8.3 or, at your option, any later
-version of Perl 5 you may have available.
-
-
-Many Thanks to:
-===============
-
-Author of bzip2:
-Julian Seward, j s e w a r d   a t   a c m . o r g
-Cambridge, UK
-http://sources.redhat.com/bzip2
-
-Author of Compress::Zlib:
-Paul Marquess, p m q s   a t   c p a n . o r g
-http://www.cpan.org
-
-Author of 1.x Compress::Bzip2 (1999)
-Gawdi Azem <azemgi@rupert.informatik.uni-stuttgart.de>
-(last known email, no longer valid)
-
-Sisyphus, helped out with win32 compatibility
-s i s y p h u s 1   a t   o p t u s n e t . c o m . a u
-
-Marco "Kiko" Carnut, author of Compress::Bzip2 1.03
-k i k o   a t   t e m p e s t . c o m . b r
-
@@ -0,0 +1,101 @@
+
+# Compress::Bzip2
+
+### DESCRIPTION
+
+This module provides a Compress::Zlib like Perl interface to the bzip2
+library.  It uses the low level interface to the bzip2 algorithm, and
+reimplements all high level routines.
+
+### What is Bzip2 ?
+
+bzip2 is a portable lossless data compression library written in ANSI C.
+It offers pretty fast compression and fast decompression.
+bzip2 has very good results, if you want to compress ASCII Documents.
+
+bzip2 is probably not great for streaming compression.  It fills it's
+internal buffer, which depending of parameters is between 100k and 900k
+in size, before it outputs ANY compressed data.  It works best compressing
+an entire document.
+
+Streaming decompression on the other hand, gives a steady torrent of bytes.
+
+### What is Compress::Bzip2 ?
+
+Compress::Bzip2 provided early bzip2 bindings for Perl5 compatible to
+the old Compress::Zlib library. See Compress::Raw::Bzip2 for the new API
+compatible with IO::Compress.
+
+It's my intent to make this package like the Compress::Zlib package, so
+that code that uses one can fairly easily use the other.  The perlxs stuff
+that's visible to perl has methods that have the same names as their
+Compress::Zlib counterparts, except that the "g" is changed to a "b".
+
+Most code that uses Compress::Zlib should be able to use this package.
+Simply change
+```
+
+   $gz = Compress::Zlib::gzopen( "filename", "w" );
+   
+```
+
+to
+```
+
+   $gz = Compress::Bzip2::gzopen( "filename", "w" );
+  ```
+
+I made aliases of all the Compress::Zlib functions.  Some of them don't
+return anything useful, like crc32 or adler32, cause bzip2 doesn't
+do that sort of thing.  Take a look at t/070-gzcomp.t and t/071-gzuncomp.t.
+
+Bug fixes and other feedback are welcome.
+
+### Copyright
+
+bzip2
+
+**Julian Seward**, j s e w a r d   a t   a c m . o r g
+
+Compress-Bzip2 prior to 2.0 is distributed under the terms of the
+GNU General Public License (GPL).  See the file COPYING.
+
+Since version 2.0 Compress-Bzip2 is dual-licensed.
+You can redistribute it and/or modify it under the same terms as Perl
+itself, either Perl version 5.8.3 or, at your option, any later
+version of Perl 5 you may have available.
+
+
+### Many Thanks to:
+
+
+**Author of bzip2**
+
+Julian Seward, j s e w a r d   a t   a c m . o r g
+
+Cambridge, UK
+
+http://sources.redhat.com/bzip2
+
+**Author of Compress::Zlib**
+
+Paul Marquess, p m q s   a t   c p a n . o r g
+
+http://www.cpan.org
+
+**Author of 1.x Compress::Bzip2 (1999)**
+
+Gawdi Azem <azemgi@rupert.informatik.uni-stuttgart.de>
+
+(last known email, no longer valid)
+
+**Helped out with win32 compatibility**
+
+Sisyphus, s i s y p h u s 1   a t   o p t u s n e t . c o m . a u
+
+**Author of Compress::Bzip2 1.03**
+
+Marco "Kiko" Carnut,
+ 
+k i k o   a t   t e m p e s t . c o m . b r
+
@@ -14,17 +14,18 @@ not run its Makefile.PL or Build.PL.
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
+SHA1 5fefc9642a4998a5d73d0ed2faa02a30aee2d623 .gitignore
 SHA1 321030dcade0d87dba537aff99fcba66230971d0 ANNOUNCE
-SHA1 d8094d7a2ccce1ff3a3fc69a76c73dd15291cc65 Bzip2.xs
+SHA1 9dc701d0dcdd70d36b6709b0b7674f82e032ba6f Bzip2.xs
 SHA1 ff8688f52f05aa77ac2522c7970e6ab23bf77d0e COPYING
-SHA1 34d0cd033b45d10f7202b6c45bbc46e34b3928ea Changes
+SHA1 6d50308131c0d0ab2426cd01157123727eef06b9 Changes
 SHA1 06186a4d62ebec3ffac9a4f5457458436d7302c5 INSTALL
-SHA1 dd1e07a034c254f94c1ee14562aeac83a653d3b1 MANIFEST
-SHA1 d98cd84034af6fc7a56f77ebd5e5fbc4a5ab636d META.json
-SHA1 555572c6f28761ac08fc62423188af180c89a2e9 META.yml
-SHA1 37454ac6a9d9000cf85c79514e6a0344da309a1e Makefile.PL
+SHA1 942a82ca0fe099fe66ffbd1e8e1967d1097f5a65 MANIFEST
+SHA1 94a04518755eec6c7a876fdcbd99496745278aaf META.json
+SHA1 9b3aa715c02bd11703c3d850d363fa2f14fccf9d META.yml
+SHA1 3711bef030207705a281125394be7eb9627a79a3 Makefile.PL
 SHA1 01ca12f980ac0675ebc82d84c432bbf3be80c74c NEWS
-SHA1 53f65a059d9303153d8b54300636fbd81560e639 README
+SHA1 8343eaf8bfc7836c110d55b878ce13b9b56dd468 README.md
 SHA1 6bdb898b814cca277ba465b15a14eb50bc458ea8 bzlib-src/CHANGES
 SHA1 1c0c6888759a63c32bca7eb63353af2cd9bd5d9e bzlib-src/LICENSE
 SHA1 ec798819dffc496d45bab5ee665eabcc6b141c5d bzlib-src/Makefile.PL
@@ -89,7 +90,7 @@ SHA1 b7413608a39898b0e9f5009e2f32ad7e3356956d bzlib-src/xmlproc.sh
 SHA1 7dfc2194e9b344251a52ae5b6399fb1650342905 config.in
 SHA1 f51e8905cd4c7ac9abe672ead1f8a52b82fbbad5 fallback/const-c.inc
 SHA1 340a622d47ec2642d9631c79432f1c234a6c8c84 fallback/const-xs.inc
-SHA1 81020db2b7eebabde63d31b00541c9a146b79af0 lib/Compress/Bzip2.pm
+SHA1 90d0f9a890ce9cc38477019767918a398da91dd0 lib/Compress/Bzip2.pm
 SHA1 fb7154b5f5ab3dd33064a2a1ac704f596dc6449a ppport.h
 SHA1 f5620dc7bc334bd571a5bceb7012cc11114cccff show_bzversion.c
 SHA1 4dd4bbbd10e755857ed1ca2beabfa6410c8ef2ca t/010-useability.t
@@ -118,7 +119,9 @@ SHA1 8b048b1a35dd9c83ac116bfb0c62fccff8909273 t/071-gzuncomp.t
 SHA1 51c2260d728eb8feac05fc2dad13ac45f9c5f1db t/080-version.t
 SHA1 59a46cac15f6e1e05b4fa719f7944b8b1b83f0a6 t/081-basic.t
 SHA1 5b6cd3c144afeb67a6b6c61389fb273d55a1ac1a t/082-stream.t
+SHA1 71c2712364069b5c6d86a3fa108d83fd487d950c t/090-memory-usage.pl
 SHA1 a68085c94808f024eb2ed76ce73ea439f0ed6d48 t/900_kwalitee.t
+SHA1 dfae3df9042df2eb88963438414a82207f9e5e1c t/900_leaktrace.t
 SHA1 993b3cef8c06a70d99829facf76140864eb57240 t/900_meta.t
 SHA1 1ce51bd4ebcb568ddd166c32d5dbb57ff2d0b515 t/900_perl_minimum_version.t
 SHA1 5d64c28fbb2d9eb5e649ac42f594d7bde8ef31e7 t/900_pod-coverage.t
@@ -126,9 +129,9 @@ SHA1 8e6c77dd1d7e2bb99d62e199e1b19b6090e405f5 t/900_pod.t
 SHA1 c77d252511eb0f1ec5403322cb21ce00ccce5aff t/lib.pl
 SHA1 d247f2120895e2fdcd1ea6e65bab1a1f68c06714 typemap
 -----BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.14 (GNU/Linux)
+Version: GnuPG v1
 
-iEYEARECAAYFAlIeHGgACgkQmm2SYo/9yUJ5bgCdGfb5MXu9B2GYIKFFFz0958n+
-bb0AnRbVm4NLe8woVJ/gvfmTigNC9UdO
-=Un13
+iEYEARECAAYFAlTls0gACgkQmm2SYo/9yUJuQQCgjwSyY09t1V1NCrRM/hzwFtUq
+Tx4AniHaobv114Uwxui/QVn+U4kLLLcr
+=5vD2
 -----END PGP SIGNATURE-----
@@ -1,8 +1,8 @@
 # File	   : Bzip2.pm
 # Author   : Rob Janes
 # Created  : 14 April 2005
-# Modified : 2013-08-28 10:44:01 rurban
-# Version  : 2.17
+# Modified : 2015-02-19 rurban
+# Version  : 2.22
 #
 #     Copyright (c) 2005 Rob Janes. All rights reserved.
 #     This program is free software; you can redistribute it and/or
@@ -12,7 +12,7 @@
 package Compress::Bzip2;
 
 use 5.006;
-our $VERSION = "2.17";
+our $VERSION = "2.22";
 use strict;
 use warnings;
 
@@ -360,7 +360,7 @@ sub _process_files ( @ ) {
 	print STDERR "Error: failed to stat $infile: '$!'\n";
 	next;
       }
-      
+
       if ( !_check_stat( $infile, \@statbuf, $opts{f} ) ) {
 	print STDERR "Error: file $infile stat check fails: $bzerrno\n";
 	next;
@@ -383,7 +383,7 @@ sub _process_files ( @ ) {
 	next;
       }
     }
-    
+
     if ( !$read_from_stdin ) {
       undef $in;
       if ( !open( $in, $infile ) ) {
@@ -445,7 +445,7 @@ sub _process_files ( @ ) {
     }
   }
 }
-  
+
 ##############################################################################
 ##############################################################################
 ## compatibility with Compress::Bzip2 1.03
@@ -682,11 +682,11 @@ Compress::Bzip2 - Interface to Bzip2 compression library
 
     use Compress::Bzip2 qw(:all :constant :utilities :gzip);
 
-    ($bz, $status) = bzdeflateInit( [PARAMS] ) ;
-    ($out, $status) = $bz->bzdeflate($buffer) ;
+    ($bz, $status) = bzdeflateInit( [PARAMS] );
+    ($out, $status) = $bz->bzdeflate($buffer) ; # compress
 
-    ($bz, $status) = bzinflateInit( [PARAMS] ) ;
-    ($out, $status) = $bz->bzinflate($buffer) ;
+    ($bz, $status) = bzinflateInit( [PARAMS] );
+    ($out, $status) = $bz->bzinflate($buffer);  # uncompress
 
     ($out, $status) = $bz->bzflush() ;
     ($out, $status) = $bz->bzclose() ;
@@ -705,7 +705,7 @@ Compress::Bzip2 - Interface to Bzip2 compression library
     $bytesread = $bz->bzread($buffer [,$size]) ;
     $bytesread = $bz->bzreadline($line);
     $byteswritten = $bz->bzwrite($buffer [,$limit]);
-    $errstring = $bz->bzerror(); 
+    $errstring = $bz->bzerror();
     $status = $bz->bzeof();
     $status = $bz->bzflush();
     $status = $bz->bzclose() ;
@@ -721,9 +721,9 @@ Compress::Bzip2 - Interface to Bzip2 compression library
 
 =head1 DESCRIPTION
 
-The I<Compress::Bzip2> module provides a Perl interface to the I<Bzip2>
+The I<Compress::Bzip2> module provides a Perl interface to the B<bzip2>
 compression library (see L</AUTHOR> for details about where to get
-I<Bzip2>). A relevant subset of the functionality provided by I<Bzip2>
+I<Bzip2>). A relevant subset of the functionality provided by I<bzip2>
 is available in I<Compress::Bzip2>.
 
 All string parameters can either be a scalar or a scalar reference.
@@ -732,6 +732,13 @@ The module can be split into two general areas of functionality, namely
 in-memory compression/decompression and read/write access to I<bzip2>
 files. Each of these areas will be discussed separately below.
 
+B<NOTE>
+
+I<Compress::Bzip2> is just a simple I<bzip2> binding, comparable to the
+old L<Compress::Zlib> library. It is not well integrated into PerlIO,
+use the preferred L<IO::Compress::Bzip2> instead.
+
+
 =head1 FILE READ/WRITE INTERFACE
 
 A number of functions are supplied in I<bzlib> for reading and writing
@@ -776,7 +783,7 @@ the case of an error, -1.
 
 =head2 B<$bytesread = $bz-E<gt>bzreadline($line) ;>
 
-Reads the next line from the compressed file into B<$line>. 
+Reads the next line from the compressed file into B<$line>.
 
 Returns the number of bytes actually read. On EOF it returns 0 and in
 the case of an error, -1.
@@ -1155,7 +1162,7 @@ The buffer parameter can either be a scalar or a scalar reference. The
 contents of the buffer parameter are destroyed after calling this
 function.
 
-=head1 STREAM DEFLATE 
+=head1 STREAM DEFLATE (= COMPRESS)
 
 The Perl interface will I<always> consume the complete input buffer
 before returning. Also the output buffer returned will be
@@ -1165,7 +1172,7 @@ Here is a definition of the interface available:
 
 =head2 B<($d, $status) = bzdeflateInit( [PARAMS] )>
 
-Initialises a deflation stream. 
+Initialises a deflation stream.
 
 If successful, it will return the initialised deflation stream, B<$d>
 and B<$status> of C<BZ_OK> in a list context. In scalar context it
@@ -1282,18 +1289,18 @@ input, deflates it and writes it to standard output.
     while (<>)
     {
         ($output, $status) = $x->bzdeflate($_) ;
-    
+
         $status == BZ_OK
             or die "deflation failed\n" ;
-    
+
         print $output ;
     }
-    
+
     ($output, $status) = $x->bzclose() ;
-    
+
     $status == BZ_OK
         or die "deflation failed\n" ;
-    
+
     print $output ;
 
 =head1 STREAM INFLATE
@@ -1302,7 +1309,7 @@ Here is a definition of the interface:
 
 =head2 B<($i, $status) = inflateInit()>
 
-Initialises an inflation stream. 
+Initialises an inflation stream.
 
 In a list context it returns the inflation stream, B<$i>, and the
 I<zlib> status code (B<$status>). In a scalar context it returns the
@@ -1371,27 +1378,27 @@ Here is an example of using B<bzinflate>.
 
     use strict ;
     use warnings ;
-    
+
     use Compress::Bzip2;
-    
+
     my $x = bzinflateInit()
        or die "Cannot create a inflation stream\n" ;
-    
+
     my $input = '' ;
     binmode STDIN;
     binmode STDOUT;
-    
+
     my ($output, $status) ;
     while (read(STDIN, $input, 4096))
     {
         ($output, $status) = $x->bzinflate(\$input) ;
-    
-        print $output 
+
+        print $output
             if $status == BZ_OK or $status == BZ_STREAM_END ;
-    
+
         last if $status != BZ_OK ;
     }
-    
+
     die "inflation failed\n"
         unless $status == BZ_STREAM_END ;
 
@@ -1403,24 +1410,24 @@ Here are some example scripts of using the interface.
 
   use strict ;
   use warnings ;
-    
+
   use Compress::Bzip2 ;
-    
+
   die "Usage: bzcat file...\n" unless @ARGV ;
-    
+
   my $file ;
-    
+
   foreach $file (@ARGV) {
     my $buffer ;
-    
-    my $bz = bzopen($file, "rb") 
+
+    my $bz = bzopen($file, "rb")
        or die "Cannot open $file: $bzerrno\n" ;
-    
+
     print $buffer while $bz->bzread($buffer) > 0 ;
-    
-    die "Error reading from $file: $bzerrno" . ($bzerrno+0) . "\n" 
+
+    die "Error reading from $file: $bzerrno" . ($bzerrno+0) . "\n"
        if $bzerrno != BZ_STREAM_END ;
-        
+
     $bz->bzclose() ;
   }
 
@@ -1428,26 +1435,26 @@ Here are some example scripts of using the interface.
 
   use strict ;
   use warnings ;
-    
+
   use Compress::Bzip2 ;
-    
+
   die "Usage: bzgrep pattern file...\n" unless @ARGV >= 2;
-    
+
   my $pattern = shift ;
-    
+
   my $file ;
-    
+
   foreach $file (@ARGV) {
-    my $bz = bzopen($file, "rb") 
+    my $bz = bzopen($file, "rb")
        or die "Cannot open $file: $bzerrno\n" ;
-    
+
     while ($bz->bzreadline($_) > 0) {
       print if /$pattern/ ;
     }
-    
-    die "Error reading from $file: $bzerrno\n" 
+
+    die "Error reading from $file: $bzerrno\n"
       if $bzerrno != Z_STREAM_END ;
-        
+
     $bz->bzclose() ;
   }
 
@@ -1459,14 +1466,14 @@ output.
 
   use strict ;
   use warnings ;
-    
+
   use Compress::Bzip2 ;
-    
+
   binmode STDOUT;	# bzopen only sets it on the fd
-    
+
   my $bz = bzopen(\*STDOUT, "wb")
      or die "Cannot open stdout: $bzerrno\n" ;
-    
+
   while (<>) {
     $bz->bzwrite($_) or die "error writing: $bzerrno\n" ;
   }
@@ -0,0 +1,59 @@
+#! perl
+use strict;
+use 5.006002;
+use Compress::Bzip2;
+use File::Spec;
+use Memory::Usage;
+# Note that Test::LeakTrace does not find the XS leaks here. Always use Memory::Usage also.
+
+use constant MAX   => 5; # MAX times all files in t => 125MB with 75, 15MB with 5, 43MB with 25
+use constant MAX_5 => MAX >= 5 ? MAX / 5 : 1;
+my $bigfile = File::Spec->catfile('t', '090-tmp-bigfile.bz2');
+
+sub t_compress {
+  warn "Creating $bigfile ...\n";
+  my $buf;
+  my $mu = Memory::Usage->new();
+  $mu->record("Before bzopen");
+  my $bz = Compress::Bzip2::bzopen($bigfile, "w");
+  for (0 .. MAX) {
+    $mu->record("Before bzwrite: $_") unless $_ % MAX_5;
+    for my $infile (glob "t/*") {
+      next if $infile eq $bigfile;
+      open(my $fh, "<", $infile);
+      while ( read( $fh, $buf, 65335 ) ) {
+        $bz->bzwrite( $buf );
+      }
+      close $fh;
+    }
+    $mu->record("After bzwrite: $_") unless $_ % MAX_5;
+  }
+  $bz->bzclose;
+  $mu->record("After bzclose");
+  $mu->dump();
+  system("bunzip2", "-tv", $bigfile);
+  warn("  size: ", -s $bigfile, "\n");
+}
+
+sub t_uncompress {
+  warn "Uncompressing $bigfile 5x ...\n";
+  my $buf;
+  my $mu = Memory::Usage->new();
+  for ( 1 .. 5 ) {
+    my $bz = Compress::Bzip2::bzinflateInit( -verbosity => 0 );
+    $mu->record("Before bunzip: $_");
+    open( my $fh, '<', $bigfile );
+    while ( read( $fh, $buf, 65335 ) ) {
+        my ( $output, $status ) = $bz->bzinflate( $buf );
+    }
+    close($fh);
+    $bz->bzclose();
+    $mu->record("After bunzip: $_");
+  }
+  $mu->dump();
+}
+
+t_compress() unless -f $bigfile;
+t_uncompress();
+
+unlink $bigfile;
@@ -0,0 +1,31 @@
+#!perl -w
+
+use strict;
+use constant HAS_LEAKTRACE => eval{ require Test::LeakTrace };
+use Test::More HAS_LEAKTRACE ? (tests => 2) : (skip_all => 'require Test::LeakTrace');
+use Test::LeakTrace;
+
+use Compress::Bzip2;
+my $string = q/
+Twas brillig and the slithy toves
+did gire and gimble in the wabe
+All mimsey were the borogroves
+and the Momewrathes outgrabe
+    / x 20;
+
+leaks_cmp_ok{
+  my $compress = memBzip( $string );
+  my $uncompress = memBunzip( $compress );
+} '<', 1;
+
+do 't/lib.pl';
+
+leaks_cmp_ok{
+  my $INFILE = catfile( qw(bzlib-src sample0.bz2) );
+  local $/ = undef;
+  open( IN, "< $INFILE" ) or die "$INFILE: $!";
+  binmode IN;
+  my $sample0 = <IN>;
+  close( IN );
+  my $uncompress = memBunzip( $sample0 );
+} '<', 1;