aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar David G. Quintas <dgq@google.com>2017-04-14 18:14:36 -0700
committerGravatar GitHub <noreply@github.com>2017-04-14 18:14:36 -0700
commit644e05e79ba04fb0f424cbb8dffce6c3cd3913ec (patch)
tree473bb54d4fee8c576f22e882a62e5e60780f5318
parent52ff44f0d6e5af8428bc9a868593f20c954133dc (diff)
parent2f4679ea348637cd5882ace228f2dc6bc0649d4c (diff)
Merge pull request #10664 from dgquintas/http_filter_slices
Fix handling of slice in http_client_filter
-rw-r--r--include/grpc/slice.h6
-rw-r--r--src/core/ext/filters/http/client/http_client_filter.c4
2 files changed, 4 insertions, 6 deletions
diff --git a/include/grpc/slice.h b/include/grpc/slice.h
index ea66e094e9..8c32a30d76 100644
--- a/include/grpc/slice.h
+++ b/include/grpc/slice.h
@@ -102,9 +102,9 @@ GPRAPI grpc_slice grpc_slice_from_static_string(const char *source);
/* Create a slice pointing to constant memory */
GPRAPI grpc_slice grpc_slice_from_static_buffer(const void *source, size_t len);
-/* Return a result slice derived from s, which shares a ref count with s, where
- result.data==s.data+begin, and result.length==end-begin.
- The ref count of s is increased by one.
+/* Return a result slice derived from s, which shares a ref count with \a s,
+ where result.data==s.data+begin, and result.length==end-begin. The ref count
+ of \a s is increased by one. Do not assign result back to \a s.
Requires s initialized, begin <= end, begin <= s.length, and
end <= source->length. */
GPRAPI grpc_slice grpc_slice_sub(grpc_slice s, size_t begin, size_t end);
diff --git a/src/core/ext/filters/http/client/http_client_filter.c b/src/core/ext/filters/http/client/http_client_filter.c
index 63b33ccef4..bf5fbc7da7 100644
--- a/src/core/ext/filters/http/client/http_client_filter.c
+++ b/src/core/ext/filters/http/client/http_client_filter.c
@@ -323,7 +323,6 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx,
estimated_len += grpc_base64_estimate_encoded_size(
op->payload->send_message.send_message->length, k_url_safe,
k_multi_line);
- estimated_len += 1; /* for the trailing 0 */
grpc_slice path_with_query_slice = grpc_slice_malloc(estimated_len);
/* memcopy individual pieces into this slice */
@@ -345,7 +344,7 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx,
char *t = (char *)GRPC_SLICE_START_PTR(path_with_query_slice);
/* safe to use strlen since base64_encode will always add '\0' */
path_with_query_slice =
- grpc_slice_sub(path_with_query_slice, 0, strlen(t));
+ grpc_slice_sub_no_ref(path_with_query_slice, 0, strlen(t));
/* substitute previous path with the new path+query */
grpc_mdelem mdelem_path_and_query = grpc_mdelem_from_slices(
@@ -359,7 +358,6 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx,
calld->on_complete = op->on_complete;
op->on_complete = &calld->hc_on_complete;
op->send_message = false;
- grpc_slice_unref_internal(exec_ctx, path_with_query_slice);
} else {
/* Not all data is available. Fall back to POST. */
gpr_log(GPR_DEBUG,