From 4e4033650911582617049643fb02942a114be220 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Wed, 1 Jul 2015 16:45:34 -0700 Subject: Fixed leaks --- src/core/channel/compress_filter.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/core/channel') diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 6100a90668..56e0a8141e 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -67,7 +67,9 @@ static int compress_send_sb(grpc_compression_algorithm algorithm, gpr_slice_buffer tmp; gpr_slice_buffer_init(&tmp); did_compress = grpc_msg_compress(algorithm, slices, &tmp); - gpr_slice_buffer_swap(slices, &tmp); + if (did_compress) { + gpr_slice_buffer_swap(slices, &tmp); + } gpr_slice_buffer_destroy(&tmp); return did_compress; } @@ -142,8 +144,9 @@ static void process_send_ops(grpc_call_element *elem, case GRPC_OP_SLICE: if (skip_compression(channeld, calld)) continue; GPR_ASSERT(calld->remaining_slice_bytes > 0); - /* add to calld->slices */ - gpr_slice_buffer_add(&calld->slices, sop->data.slice); + /* We need to copy the input because gpr_slice_buffer_add takes + * ownership. However, we don't own sop->data.slice, the caller does. */ + gpr_slice_buffer_add(&calld->slices, gpr_slice_ref(sop->data.slice)); calld->remaining_slice_bytes -= GPR_SLICE_LENGTH(sop->data.slice); if (calld->remaining_slice_bytes == 0) { /* compress */ @@ -186,6 +189,8 @@ static void process_send_ops(grpc_call_element *elem, case GRPC_OP_SLICE: if (did_compress) { if (j < calld->slices.count) { + /* swap the input slices for their compressed counterparts */ + gpr_slice_unref(sop->data.slice); sop->data.slice = gpr_slice_ref(calld->slices.slices[j++]); } } -- cgit v1.2.3