Index: ossp-pkg/sio/sio_zlib.c RCS File: /v/ossp/cvs/ossp-pkg/sio/sio_zlib.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/sio/sio_zlib.c,v' 2>/dev/null --- sio_zlib.c 2002/11/27 13:00:44 1.1 +++ sio_zlib.c 2002/11/27 13:18:36 1.2 @@ -111,12 +111,7 @@ if (arc != AL_OK) return -1; - dt->obuf = malloc(dt->olen); - if (dt->obuf == NULL) { - al_destroy(dt->ibuf); - dt->ibuf = NULL; - return -1; - } + dt->obuf = NULL; return 0; } @@ -127,8 +122,10 @@ al_destroy(dt->ibuf); dt->ibuf = NULL; - free(dt->obuf); - dt->obuf = NULL; + if (dt->obuf != NULL) { + free(dt->obuf); + dt->obuf = NULL; + } if (dt->lvl >= 0) deflateEnd(&dt->zs); @@ -201,6 +198,12 @@ return SIO_OK; } +static +void freezlibbuf(char *p, size_t n, void *u) +{ + free(p); +} + /* * buffer logic * @@ -240,6 +243,12 @@ do { if (zs->avail_out == 0) { + if (dt->obuf == NULL && + (dt->obuf = malloc(dt->olen)) == NULL) { + arc = AL_ERR_INT; + break; + } + zs->next_out = dt->obuf; zs->avail_out = dt->olen; zs->total_out = 0; @@ -253,11 +262,14 @@ break; } if (zs->avail_out == 0 || zrc == Z_STREAM_END || flush) { - arc = al_append_bytes(dt->al, dt->obuf, zs->total_out, - my->data_label); - zs->avail_out = 0; - if (arc != AL_OK) - break; + if (zs->total_out > 0) { + arc = al_attach_buffer(dt->al, dt->obuf, zs->total_out, + my->data_label, freezlibbuf, NULL); + dt->obuf = NULL; + zs->avail_out = 0; + if (arc != AL_OK) + break; + } } } while (zs->avail_in > 0 || (zrc == Z_OK && zs->avail_out == 0));