From 45c736f48fd1b8df16382b887d117316d6cc0dfa Mon Sep 17 00:00:00 2001 From: root Date: Fri, 15 Jan 2021 20:41:07 +0000 Subject: [PATCH] add initializing start batch message buffer, fix PR#24914 --- src/php/ext/grpc/call.c | 2 +- .../generated_code/AbstractGeneratedCodeTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index e1b81f316b2..ef6b86ebb86 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -294,7 +294,7 @@ PHP_METHOD(Call, startBatch) { grpc_status_code status; grpc_slice recv_status_details = grpc_empty_slice(); grpc_slice send_status_details = grpc_empty_slice(); - grpc_byte_buffer *message; + grpc_byte_buffer *message = NULL; int cancelled; grpc_call_error error; diff --git a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php index a68954606f7..adf85637585 100644 --- a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php +++ b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php @@ -289,6 +289,20 @@ abstract class AbstractGeneratedCodeTest extends \PHPUnit\Framework\TestCase $status = $call->getStatus(); $this->assertSame(\Grpc\STATUS_OK, $status->code); } + + public function testReuseCall() + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage("start_batch was called incorrectly"); + $div_arg = new Math\DivArgs(); + $div_arg->setDividend(7); + $div_arg->setDivisor(4); + $call = self::$client->Div($div_arg, [], ['timeout' => 1000000]); + + list($response, $status) = $call->wait(); + $this->assertSame(\Grpc\STATUS_OK, $status->code); + list($response, $status) = $call->wait(); + } } class DummyInvalidClient extends \Grpc\BaseStub