aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/grpc++/impl/call.h17
-rw-r--r--include/grpc++/server.h2
-rw-r--r--src/cpp/server/server.cc1
3 files changed, 14 insertions, 6 deletions
diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h
index 94b0f915c6..9b07e2ac5e 100644
--- a/include/grpc++/impl/call.h
+++ b/include/grpc++/impl/call.h
@@ -34,7 +34,7 @@
#ifndef GRPCXX_IMPL_CALL_H
#define GRPCXX_IMPL_CALL_H
-#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
#include <grpc++/client_context.h>
#include <grpc++/completion_queue.h>
#include <grpc++/config.h>
@@ -85,6 +85,8 @@ class CallOpSendInitialMetadata {
op->data.send_initial_metadata.metadata = initial_metadata_;
}
void FinishOp(bool* status, int max_message_size) {
+ if (!send_) return;
+ gpr_free(initial_metadata_);
send_ = false;
}
@@ -244,6 +246,7 @@ class CallOpServerSendStatus {
protected:
void AddOp(grpc_op* ops, size_t* nops) {
+ if (!send_status_available_) return;
grpc_op* op = &ops[(*nops)++];
op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
op->data.send_status_from_server.trailing_metadata_count =
@@ -255,7 +258,9 @@ class CallOpServerSendStatus {
}
void FinishOp(bool* status, int max_message_size) {
- send_status_details_ = false;
+ if (!send_status_available_) return;
+ gpr_free(trailing_metadata_);
+ send_status_available_ = false;
}
private:
@@ -269,7 +274,6 @@ class CallOpServerSendStatus {
class CallOpRecvInitialMetadata {
public:
CallOpRecvInitialMetadata() : recv_initial_metadata_(nullptr) {
- memset(&recv_initial_metadata_arr_, 0, sizeof(recv_initial_metadata_arr_));
}
void RecvInitialMetadata(ClientContext* context) {
@@ -280,6 +284,7 @@ class CallOpRecvInitialMetadata {
protected:
void AddOp(grpc_op* ops, size_t* nops) {
if (!recv_initial_metadata_) return;
+ memset(&recv_initial_metadata_arr_, 0, sizeof(recv_initial_metadata_arr_));
grpc_op* op = &ops[(*nops)++];
op->op = GRPC_OP_RECV_INITIAL_METADATA;
op->data.recv_initial_metadata = &recv_initial_metadata_arr_;
@@ -297,7 +302,7 @@ class CallOpRecvInitialMetadata {
class CallOpClientRecvStatus {
public:
- CallOpClientRecvStatus() { memset(this, 0, sizeof(*this)); }
+ CallOpClientRecvStatus() : recv_status_(nullptr) {}
void ClientRecvStatus(ClientContext* context, Status* status) {
recv_trailing_metadata_ = &context->trailing_metadata_;
@@ -307,6 +312,9 @@ class CallOpClientRecvStatus {
protected:
void AddOp(grpc_op* ops, size_t* nops) {
if (recv_status_ == nullptr) return;
+ memset(&recv_trailing_metadata_arr_, 0, sizeof(recv_trailing_metadata_arr_));
+ status_details_ = nullptr;
+ status_details_capacity_ = 0;
grpc_op* op = &ops[(*nops)++];
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
op->data.recv_status_on_client.trailing_metadata =
@@ -323,6 +331,7 @@ class CallOpClientRecvStatus {
*recv_status_ = Status(
static_cast<StatusCode>(status_code_),
status_details_ ? grpc::string(status_details_) : grpc::string());
+ gpr_free(status_details_);
recv_status_ = nullptr;
}
diff --git a/include/grpc++/server.h b/include/grpc++/server.h
index cdfdc86587..834d19c882 100644
--- a/include/grpc++/server.h
+++ b/include/grpc++/server.h
@@ -108,8 +108,6 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE;
protected:
- void FinalizeMetadata(ServerContext* context);
-
Server* const server_;
ServerContext* const context_;
ServerAsyncStreamingInterface* const stream_;
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 680f96061c..ed1bb2a362 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -317,6 +317,7 @@ bool Server::BaseAsyncRequest::FinalizeResult(void** tag, bool* status) {
initial_metadata_array_.metadata[i].value_length)));
}
}
+ grpc_metadata_array_destroy(&initial_metadata_array_);
context_->call_ = call_;
context_->cq_ = call_cq_;
Call call(call_, server_, call_cq_, server_->max_message_size_);