From 1d0cc4ba6a04356a20eb676c14c50fc3c077f710 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 04:55:11 -0700 Subject: [PATCH 1/9] Set dependencies with ~> to prevent major verion breakage --- bzip2-ruby.gemspec | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bzip2-ruby.gemspec b/bzip2-ruby.gemspec index f548adc..bcee4ab 100644 --- a/bzip2-ruby.gemspec +++ b/bzip2-ruby.gemspec @@ -16,6 +16,7 @@ Gem::Specification.new do |s| s.test_files = `git ls-files spec`.split("\n") # tests - s.add_development_dependency 'rake-compiler', ">= 0.7.5" - s.add_development_dependency 'rspec', ">= 2.0.0" + s.add_development_dependency 'rake-compiler', '~> 0.8.0' + s.add_development_dependency 'rake', '~> 0.9.3' + s.add_development_dependency 'rspec', '~> 2.8.0' end From 366442f2e327c6c03dc3e116bcaeb1c97009d9eb Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 05:09:56 -0700 Subject: [PATCH 2/9] Add Ruby 2.0, 2.1, Update Rbx on Travis. --- .travis.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index cf244d4..fa3139b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,15 +3,13 @@ rvm: - 1.8.7 - 1.9.2 - 1.9.3 - - rbx + - 2.0.0 + - 2.1.2 + - rbx-2 - ree - - ruby-head - - rbx-18mode - - rbx-19mode matrix: allow_failures: - - rvm: rbx-18mode - - rvm: rbx-19mode + - rvm: rbx-2 script: - bundle exec rake - bundle exec rspec From e8deb295988f29953361e9b0b5812c0ad1395856 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 22:41:56 -0700 Subject: [PATCH 3/9] Progress on the bzf->buf double free, but something is still wrong. --- ext/bzip2/reader.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/bzip2/reader.c b/ext/bzip2/reader.c index c535799..d2eb61a 100644 --- a/ext/bzip2/reader.c +++ b/ext/bzip2/reader.c @@ -316,7 +316,8 @@ VALUE bz_reader_read(int argc, VALUE *argv, VALUE obj) { OBJ_TAINT(res); } if (n == 0) { - free(bzf->buf); + xfree(bzf->buf); + bzf->buf = NULL; return res; } while (1) { @@ -326,14 +327,16 @@ VALUE bz_reader_read(int argc, VALUE *argv, VALUE obj) { res = rb_str_cat(res, bzf->bzs.next_out, n); bzf->bzs.next_out += n; bzf->bzs.avail_out -= n; - free(bzf->buf); + xfree(bzf->buf); + bzf->buf = NULL; return res; } if (total) { res = rb_str_cat(res, bzf->bzs.next_out, total); } if (bz_next_available(bzf, 0) == BZ_STREAM_END) { - free(bzf->buf); + xfree(bzf->buf); + bzf->buf = NULL; return res; } } @@ -802,8 +805,8 @@ VALUE bz_reader_close(VALUE obj) { Get_BZ2(obj, bzf); if (bzf->buf) { - free(bzf->buf); - bzf->buf = 0; + xfree(bzf->buf); + bzf->buf = NULL; } if (bzf->state == BZ_OK) { BZ2_bzDecompressEnd(&(bzf->bzs)); @@ -837,9 +840,9 @@ VALUE bz_reader_finish(VALUE obj) { Get_BZ2(obj, bzf); if (bzf->buf) { rb_funcall2(obj, id_read, 0, 0); - free(bzf->buf); + xfree(bzf->buf); + bzf->buf = NULL; } - bzf->buf = 0; bzf->state = BZ_OK; return Qnil; } From 431864ff07c704d2f9c9fa6936c2c0e2303508ef Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 22:49:38 -0700 Subject: [PATCH 4/9] Remove Ruby < 1.8.6 workarounds --- ext/bzip2/common.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ext/bzip2/common.h b/ext/bzip2/common.h index 5a99b75..f5ebac3 100644 --- a/ext/bzip2/common.h +++ b/ext/bzip2/common.h @@ -18,20 +18,6 @@ #define DEFAULT_BLOCKS 9 #define ASIZE (1 << CHAR_BIT) -/* Older versions of Ruby (< 1.8.6) need these */ -#ifndef RSTRING_PTR -# define RSTRING_PTR(s) (RSTRING(s)->ptr) -#endif -#ifndef RSTRING_LEN -# define RSTRING_LEN(s) (RSTRING(s)->len) -#endif -#ifndef RARRAY_PTR -# define RARRAY_PTR(s) (RARRAY(s)->ptr) -#endif -#ifndef RARRAY_LEN -# define RARRAY_LEN(s) (RARRAY(s)->len) -#endif - struct bz_file { bz_stream bzs; VALUE in, io; From aac9fb3fb39ab631e24b9da287198435163fa54a Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 22:49:55 -0700 Subject: [PATCH 5/9] Remove #ifndef of never-defined thing --- ext/bzip2/common.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/bzip2/common.h b/ext/bzip2/common.h index f5ebac3..101d266 100644 --- a/ext/bzip2/common.h +++ b/ext/bzip2/common.h @@ -44,7 +44,6 @@ struct bz_iv { rb_raise(rb_eIOError, "closed IO"); \ } -#ifndef ASDFasdf extern VALUE bz_cWriter, bz_cReader, bz_cInternal; extern VALUE bz_eError, bz_eEOZError; @@ -52,7 +51,6 @@ extern VALUE bz_internal_ary; extern ID id_new, id_write, id_open, id_flush, id_read; extern ID id_closed, id_close, id_str; -#endif void bz_file_mark(struct bz_file * bzf); void* bz_malloc(void *opaque, int m, int n); From de5349e83289c7f551742614b2b6d55f7abf3861 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 23:06:39 -0700 Subject: [PATCH 6/9] bz_raise does not return --- ext/bzip2/common.c | 2 +- ext/bzip2/common.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/bzip2/common.c b/ext/bzip2/common.c index dd7e5d5..d845428 100644 --- a/ext/bzip2/common.c +++ b/ext/bzip2/common.c @@ -16,7 +16,7 @@ void bz_free(void *opaque, void *p) { free(p); } -VALUE bz_raise(int error) { +void bz_raise(int error) { VALUE exc; const char *msg; diff --git a/ext/bzip2/common.h b/ext/bzip2/common.h index 101d266..5b00420 100644 --- a/ext/bzip2/common.h +++ b/ext/bzip2/common.h @@ -55,6 +55,6 @@ extern ID id_closed, id_close, id_str; void bz_file_mark(struct bz_file * bzf); void* bz_malloc(void *opaque, int m, int n); void bz_free(void *opaque, void *p); -VALUE bz_raise(int err); +void bz_raise(int err); #endif From 75b02b56eecee7d82168b4105d4620967977f114 Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 23:41:52 -0700 Subject: [PATCH 7/9] This resolves the failures from freeing bzf->buf too soon. --- ext/bzip2/reader.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ext/bzip2/reader.c b/ext/bzip2/reader.c index d2eb61a..b5b956b 100644 --- a/ext/bzip2/reader.c +++ b/ext/bzip2/reader.c @@ -327,16 +327,12 @@ VALUE bz_reader_read(int argc, VALUE *argv, VALUE obj) { res = rb_str_cat(res, bzf->bzs.next_out, n); bzf->bzs.next_out += n; bzf->bzs.avail_out -= n; - xfree(bzf->buf); - bzf->buf = NULL; return res; } if (total) { res = rb_str_cat(res, bzf->bzs.next_out, total); } if (bz_next_available(bzf, 0) == BZ_STREAM_END) { - xfree(bzf->buf); - bzf->buf = NULL; return res; } } From 9c12b10f98a20168895832b44581af6372e89cfc Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 23:47:10 -0700 Subject: [PATCH 8/9] Random guess at where to free --- ext/bzip2/reader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/bzip2/reader.c b/ext/bzip2/reader.c index b5b956b..7b67631 100644 --- a/ext/bzip2/reader.c +++ b/ext/bzip2/reader.c @@ -316,8 +316,6 @@ VALUE bz_reader_read(int argc, VALUE *argv, VALUE obj) { OBJ_TAINT(res); } if (n == 0) { - xfree(bzf->buf); - bzf->buf = NULL; return res; } while (1) { @@ -336,6 +334,8 @@ VALUE bz_reader_read(int argc, VALUE *argv, VALUE obj) { return res; } } + xfree(bzf->buf); + bzf->buf = NULL; return Qnil; } From 1fd4deded38d460dc123ebeeb26e7e2834c944ac Mon Sep 17 00:00:00 2001 From: Aaron Stone Date: Tue, 3 Jun 2014 23:49:23 -0700 Subject: [PATCH 9/9] This completes reverting that one --- ext/bzip2/reader.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/bzip2/reader.c b/ext/bzip2/reader.c index 7b67631..1953262 100644 --- a/ext/bzip2/reader.c +++ b/ext/bzip2/reader.c @@ -334,8 +334,6 @@ VALUE bz_reader_read(int argc, VALUE *argv, VALUE obj) { return res; } } - xfree(bzf->buf); - bzf->buf = NULL; return Qnil; }