mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
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:
parent
db3ae72d19
commit
12b084b621
@ -495,6 +495,7 @@ static bool channel_write(Channel *channel, WBuffer *buffer)
|
||||
bool success;
|
||||
|
||||
if (channel->closed) {
|
||||
wstream_release_wbuffer(buffer);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user