Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve memory leak in cronet_transport #8256

Merged
merged 3 commits into from
Oct 5, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update free_read_buffer with a function
  • Loading branch information
Muxi Yan committed Oct 3, 2016
commit 92795c405c3961441182f29a9356cf589bb70190
24 changes: 12 additions & 12 deletions src/core/ext/transport/cronet/transport/cronet_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@
if (grpc_cronet_trace) gpr_log(__VA_ARGS__); \
} while (0)

#define free_read_buffer(state_rs) \
if ((state_rs).read_buffer && \
(state_rs).read_buffer != (state_rs).grpc_header_bytes) { \
gpr_free((state_rs).read_buffer); \
(state_rs).read_buffer = NULL; \
}


/* TODO (makdharma): Hook up into the wider tracing mechanism */
int grpc_cronet_trace = 0;

Expand Down Expand Up @@ -247,6 +239,14 @@ static const char *op_id_string(enum e_op_id i) {
return "UNKNOWN";
}

static void free_read_buffer(stream_obj *s) {
if (s->state.rs.read_buffer &&
s->state.rs.read_buffer != s->state.rs.grpc_header_bytes) {
gpr_free(s->state.rs.read_buffer);
s->state.rs.read_buffer = NULL;
}
}

/*
Add a new stream op to op storage.
*/
Expand Down Expand Up @@ -349,7 +349,7 @@ static void on_failed(cronet_bidirectional_stream *stream, int net_error) {
gpr_free(s->state.ws.write_buffer);
s->state.ws.write_buffer = NULL;
}
free_read_buffer(s->state.rs);
free_read_buffer(s);
gpr_mu_unlock(&s->mu);
execute_from_storage(s);
}
Expand All @@ -372,7 +372,7 @@ static void on_canceled(cronet_bidirectional_stream *stream) {
gpr_free(s->state.ws.write_buffer);
s->state.ws.write_buffer = NULL;
}
free_read_buffer(s->state.rs);
free_read_buffer(s);
gpr_mu_unlock(&s->mu);
execute_from_storage(s);
}
Expand All @@ -387,7 +387,7 @@ static void on_succeeded(cronet_bidirectional_stream *stream) {
cronet_bidirectional_stream_destroy(s->cbs);
s->state.state_callback_received[OP_SUCCEEDED] = true;
s->cbs = NULL;
free_read_buffer(s->state.rs);
free_read_buffer(s);
gpr_mu_unlock(&s->mu);
execute_from_storage(s);
}
Expand Down Expand Up @@ -912,7 +912,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx,
uint8_t *dst_p = GPR_SLICE_START_PTR(read_data_slice);
memcpy(dst_p, stream_state->rs.read_buffer,
(size_t)stream_state->rs.length_field);
free_read_buffer(stream_state->rs);
free_read_buffer(s);
gpr_slice_buffer_init(&stream_state->rs.read_slice_buffer);
gpr_slice_buffer_add(&stream_state->rs.read_slice_buffer,
read_data_slice);
Expand Down