Fix a memory leak for WBuffers used in channel_write().

channel_write() uses a ref-counted buffer for writing. This buffer
should be released if it was used in "refcount" channel_write() calls.
But calling channel_write() on a closed channel would return early and
not decrease the refcount of the used buffer.
This commit is contained in:
oni-link 2015-02-12 14:07:05 +01:00 committed by Thiago de Arruda
parent db3ae72d19
commit 12b084b621
2 changed files with 4 additions and 3 deletions

View File

@ -495,6 +495,7 @@ static bool channel_write(Channel *channel, WBuffer *buffer)
bool success;
if (channel->closed) {
wstream_release_wbuffer(buffer);
return false;
}

View File

@ -181,7 +181,7 @@ bool wstream_write(WStream *wstream, WBuffer *buffer)
return true;
err:
release_wbuffer(buffer);
wstream_release_wbuffer(buffer);
return false;
}
@ -217,7 +217,7 @@ static void write_cb(uv_write_t *req, int status)
data->wstream->curmem -= data->buffer->size;
release_wbuffer(data->buffer);
wstream_release_wbuffer(data->buffer);
if (data->wstream->cb) {
data->wstream->cb(data->wstream,
@ -239,7 +239,7 @@ static void write_cb(uv_write_t *req, int status)
kmp_free(WRequestPool, wrequest_pool, data);
}
static void release_wbuffer(WBuffer *buffer)
void wstream_release_wbuffer(WBuffer *buffer)
{
if (!--buffer->refcount) {
if (buffer->cb) {