From aa11066573722b704c718f418514735f1c86edb6 Mon Sep 17 00:00:00 2001
From: murgatroid99 <mlumish@google.com>
Date: Wed, 8 Apr 2015 16:53:47 -0700
Subject: [PATCH] Fixed memory leaks in PHP extension code

---
 src/php/ext/grpc/call.c    | 11 +++++++----
 src/php/ext/grpc/channel.c |  1 +
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c
index 6bc65b5367..b1525e9246 100644
--- a/src/php/ext/grpc/call.c
+++ b/src/php/ext/grpc/call.c
@@ -443,8 +443,9 @@ PHP_METHOD(Call, startBatch) {
         add_property_bool(result, "send_status", true);
         break;
       case GRPC_OP_RECV_INITIAL_METADATA:
-        add_property_zval(result, "metadata",
-                          grpc_parse_metadata_array(&recv_metadata));
+        array = grpc_parse_metadata_array(&recv_metadata);
+        add_property_zval(result, "metadata", array);
+        Z_DELREF_P(array);
         break;
       case GRPC_OP_RECV_MESSAGE:
         byte_buffer_to_string(message, &message_str, &message_len);
@@ -458,11 +459,13 @@ PHP_METHOD(Call, startBatch) {
       case GRPC_OP_RECV_STATUS_ON_CLIENT:
         MAKE_STD_ZVAL(recv_status);
         object_init(recv_status);
-        add_property_zval(recv_status, "metadata",
-                          grpc_parse_metadata_array(&recv_trailing_metadata));
+        array = grpc_parse_metadata_array(&recv_trailing_metadata);
+        add_property_zval(recv_status, "metadata", array);
+        Z_DELREF_P(array);
         add_property_long(recv_status, "code", status);
         add_property_string(recv_status, "details", status_details, true);
         add_property_zval(result, "status", recv_status);
+        Z_DELREF_P(recv_status);
         break;
       case GRPC_OP_RECV_CLOSE_ON_SERVER:
         add_property_bool(result, "cancelled", cancelled);
diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c
index 51a3eae0f4..b8262db162 100644
--- a/src/php/ext/grpc/channel.c
+++ b/src/php/ext/grpc/channel.c
@@ -62,6 +62,7 @@ void free_wrapped_grpc_channel(void *object TSRMLS_DC) {
   if (channel->wrapped != NULL) {
     grpc_channel_destroy(channel->wrapped);
   }
+  efree(channel->target);
   efree(channel);
 }
 
-- 
GitLab