1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/zlib/zlib.c (rb_deflate_s_deflate, rb_inflate_s_inflate): ensure

freeing internal zstreams.  fixed: [ruby-dev:25309]

* ext/zlib/zlib.c (rb_deflate_init_copy): replace rb_deflate_clone.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2004-12-28 04:36:21 +00:00
parent 53c584d35d
commit 83ef3cd8a6
2 changed files with 52 additions and 26 deletions

View file

@ -1,3 +1,10 @@
Tue Dec 28 13:35:20 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/zlib/zlib.c (rb_deflate_s_deflate, rb_inflate_s_inflate): ensure
freeing internal zstreams. fixed: [ruby-dev:25309]
* ext/zlib/zlib.c (rb_deflate_init_copy): replace rb_deflate_clone.
Mon Dec 27 20:02:14 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Mon Dec 27 20:02:14 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c: fix SEGV bug when deleting Tk interp * ext/tcltklib/tcltklib.c: fix SEGV bug when deleting Tk interp

View file

@ -55,7 +55,7 @@ static void zstream_reset_input _((struct zstream*));
static void zstream_passthrough_input _((struct zstream*)); static void zstream_passthrough_input _((struct zstream*));
static VALUE zstream_detach_input _((struct zstream*)); static VALUE zstream_detach_input _((struct zstream*));
static void zstream_reset _((struct zstream*)); static void zstream_reset _((struct zstream*));
static void zstream_end _((struct zstream*)); static VALUE zstream_end _((struct zstream*));
static void zstream_run _((struct zstream*, Bytef*, uInt, int)); static void zstream_run _((struct zstream*, Bytef*, uInt, int));
static VALUE zstream_sync _((struct zstream*, Bytef*, uInt)); static VALUE zstream_sync _((struct zstream*, Bytef*, uInt));
static void zstream_mark _((struct zstream*)); static void zstream_mark _((struct zstream*));
@ -80,7 +80,8 @@ static VALUE rb_zstream_closed_p _((VALUE));
static VALUE rb_deflate_s_allocate _((VALUE)); static VALUE rb_deflate_s_allocate _((VALUE));
static VALUE rb_deflate_initialize _((int, VALUE*, VALUE)); static VALUE rb_deflate_initialize _((int, VALUE*, VALUE));
static VALUE rb_deflate_clone _((VALUE)); static VALUE rb_deflate_init_copy _((VALUE, VALUE));
static VALUE deflate_run _((VALUE));
static VALUE rb_deflate_s_deflate _((int, VALUE*, VALUE)); static VALUE rb_deflate_s_deflate _((int, VALUE*, VALUE));
static void do_deflate _((struct zstream*, VALUE, int)); static void do_deflate _((struct zstream*, VALUE, int));
static VALUE rb_deflate_deflate _((int, VALUE*, VALUE)); static VALUE rb_deflate_deflate _((int, VALUE*, VALUE));
@ -89,6 +90,7 @@ static VALUE rb_deflate_flush _((int, VALUE*, VALUE));
static VALUE rb_deflate_params _((VALUE, VALUE, VALUE)); static VALUE rb_deflate_params _((VALUE, VALUE, VALUE));
static VALUE rb_deflate_set_dictionary _((VALUE, VALUE)); static VALUE rb_deflate_set_dictionary _((VALUE, VALUE));
static VALUE inflate_run _((VALUE));
static VALUE rb_inflate_s_allocate _((VALUE)); static VALUE rb_inflate_s_allocate _((VALUE));
static VALUE rb_inflate_initialize _((int, VALUE*, VALUE)); static VALUE rb_inflate_initialize _((int, VALUE*, VALUE));
static VALUE rb_inflate_s_inflate _((VALUE, VALUE)); static VALUE rb_inflate_s_inflate _((VALUE, VALUE));
@ -670,7 +672,7 @@ zstream_reset(z)
zstream_reset_input(z); zstream_reset_input(z);
} }
static void static VALUE
zstream_end(z) zstream_end(z)
struct zstream *z; struct zstream *z;
{ {
@ -695,6 +697,7 @@ zstream_end(z)
raise_zlib_error(err, z->stream.msg); raise_zlib_error(err, z->stream.msg);
} }
z->flags = 0; z->flags = 0;
return Qnil;
} }
static void static void
@ -1155,26 +1158,31 @@ rb_deflate_initialize(argc, argv, obj)
* Duplicates the deflate stream. * Duplicates the deflate stream.
*/ */
static VALUE static VALUE
rb_deflate_clone(obj) rb_deflate_init_copy(self, orig)
VALUE obj; VALUE self, orig;
{ {
struct zstream *z = get_zstream(obj); struct zstream *z1 = get_zstream(self);
struct zstream *z2; struct zstream *z2 = get_zstream(orig);
VALUE clone;
int err; int err;
clone = zstream_deflate_new(rb_class_of(obj)); err = deflateCopy(&z1->stream, &z2->stream);
Data_Get_Struct(clone, struct zstream, z2);
err = deflateCopy(&z2->stream, &z->stream);
if (err != Z_OK) { if (err != Z_OK) {
raise_zlib_error(err, 0); raise_zlib_error(err, 0);
} }
z1->flags = z2->flags;
z2->flags = z->flags; return self;
CLONESETUP(clone, obj); }
OBJ_INFECT(clone, obj);
return clone; static VALUE
deflate_run(args)
VALUE args;
{
struct zstream *z = (struct zstream *)((VALUE *)args)[0];
VALUE src = ((VALUE *)args)[1];
zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_FINISH);
return zstream_detach_buffer(z);
} }
/* /*
@ -1204,7 +1212,7 @@ rb_deflate_s_deflate(argc, argv, klass)
VALUE klass; VALUE klass;
{ {
struct zstream z; struct zstream z;
VALUE src, level, dst; VALUE src, level, dst, args[2];
int err, lev; int err, lev;
rb_scan_args(argc, argv, "11", &src, &level); rb_scan_args(argc, argv, "11", &src, &level);
@ -1218,9 +1226,9 @@ rb_deflate_s_deflate(argc, argv, klass)
} }
ZSTREAM_READY(&z); ZSTREAM_READY(&z);
zstream_run(&z, RSTRING(src)->ptr, RSTRING(src)->len, Z_FINISH); args[0] = (VALUE)&z;
dst = zstream_detach_buffer(&z); args[1] = src;
zstream_end(&z); dst = rb_ensure(deflate_run, (VALUE)args, zstream_end, (VALUE)&z);
OBJ_INFECT(dst, src); OBJ_INFECT(dst, src);
return dst; return dst;
@ -1433,6 +1441,18 @@ rb_inflate_initialize(argc, argv, obj)
return obj; return obj;
} }
static VALUE
inflate_run(args)
VALUE args;
{
struct zstream *z = (struct zstream *)((VALUE *)args)[0];
VALUE src = ((VALUE *)args)[1];
zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
zstream_run(z, "", 0, Z_FINISH); /* for checking errors */
return zstream_detach_buffer(z);
}
/* /*
* call-seq: Zlib::Inflate.inflate(string) * call-seq: Zlib::Inflate.inflate(string)
* *
@ -1455,7 +1475,7 @@ rb_inflate_s_inflate(obj, src)
VALUE obj, src; VALUE obj, src;
{ {
struct zstream z; struct zstream z;
VALUE dst; VALUE dst, args[2];
int err; int err;
StringValue(src); StringValue(src);
@ -1466,10 +1486,9 @@ rb_inflate_s_inflate(obj, src)
} }
ZSTREAM_READY(&z); ZSTREAM_READY(&z);
zstream_run(&z, RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH); args[0] = (VALUE)&z;
zstream_run(&z, "", 0, Z_FINISH); /* for checking errors */ args[1] = src;
dst = zstream_detach_buffer(&z); dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)&z);
zstream_end(&z);
OBJ_INFECT(dst, src); OBJ_INFECT(dst, src);
return dst; return dst;
@ -3438,7 +3457,7 @@ void Init_zlib()
rb_define_singleton_method(cDeflate, "deflate", rb_deflate_s_deflate, -1); rb_define_singleton_method(cDeflate, "deflate", rb_deflate_s_deflate, -1);
rb_define_alloc_func(cDeflate, rb_deflate_s_allocate); rb_define_alloc_func(cDeflate, rb_deflate_s_allocate);
rb_define_method(cDeflate, "initialize", rb_deflate_initialize, -1); rb_define_method(cDeflate, "initialize", rb_deflate_initialize, -1);
rb_define_method(cDeflate, "clone", rb_deflate_clone, 0); rb_define_method(cDeflate, "initialize_copy", rb_deflate_init_copy, 0);
rb_define_method(cDeflate, "deflate", rb_deflate_deflate, -1); rb_define_method(cDeflate, "deflate", rb_deflate_deflate, -1);
rb_define_method(cDeflate, "<<", rb_deflate_addstr, 1); rb_define_method(cDeflate, "<<", rb_deflate_addstr, 1);
rb_define_method(cDeflate, "flush", rb_deflate_flush, -1); rb_define_method(cDeflate, "flush", rb_deflate_flush, -1);