php: fix call metadata leak

pull/14148/head
Zhouyihai Ding 7 years ago
parent 2c5964fffc
commit bc953bc53f
  1. 16
      src/php/ext/grpc/call.c
  2. 3
      src/php/ext/grpc/call.h

@ -174,6 +174,18 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
return true;
}
void grpc_php_metadata_array_destroy_including_entries(
grpc_metadata_array* array) {
size_t i;
if (array->metadata) {
for (i = 0; i < array->count; i++) {
grpc_slice_unref(array->metadata[i].key);
grpc_slice_unref(array->metadata[i].value);
}
}
grpc_metadata_array_destroy(array);
}
/* Wraps a grpc_call struct in a PHP object. Owned indicates whether the
struct should be destroyed at the end of the object's lifecycle */
zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) {
@ -502,8 +514,8 @@ PHP_METHOD(Call, startBatch) {
}
cleanup:
grpc_metadata_array_destroy(&metadata);
grpc_metadata_array_destroy(&trailing_metadata);
grpc_php_metadata_array_destroy_including_entries(&metadata);
grpc_php_metadata_array_destroy_including_entries(&trailing_metadata);
grpc_metadata_array_destroy(&recv_metadata);
grpc_metadata_array_destroy(&recv_trailing_metadata);
grpc_slice_unref(recv_status_details);

@ -69,5 +69,6 @@ void grpc_init_call(TSRMLS_D);
/* Populates a grpc_metadata_array with the data in a PHP array object.
Returns true on success and false on failure */
bool create_metadata_array(zval *array, grpc_metadata_array *metadata);
void grpc_php_metadata_array_destroy_including_entries(
grpc_metadata_array* array);
#endif /* NET_GRPC_PHP_GRPC_CHANNEL_H_ */

Loading…
Cancel
Save