Merge pull request #13660 from ZhouyihaiDing/php-memory-leak

PHP: unref key and value in metadata
pull/14129/head
Stanley Cheung 7 years ago committed by GitHub
commit b609da577c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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; 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 /* 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 */ struct should be destroyed at the end of the object's lifecycle */
zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) { zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned TSRMLS_DC) {
@ -502,8 +514,8 @@ PHP_METHOD(Call, startBatch) {
} }
cleanup: cleanup:
grpc_metadata_array_destroy(&metadata); grpc_php_metadata_array_destroy_including_entries(&metadata);
grpc_metadata_array_destroy(&trailing_metadata); grpc_php_metadata_array_destroy_including_entries(&trailing_metadata);
grpc_metadata_array_destroy(&recv_metadata); grpc_metadata_array_destroy(&recv_metadata);
grpc_metadata_array_destroy(&recv_trailing_metadata); grpc_metadata_array_destroy(&recv_trailing_metadata);
grpc_slice_unref(recv_status_details); 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. /* Populates a grpc_metadata_array with the data in a PHP array object.
Returns true on success and false on failure */ Returns true on success and false on failure */
bool create_metadata_array(zval *array, grpc_metadata_array *metadata); 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_ */ #endif /* NET_GRPC_PHP_GRPC_CHANNEL_H_ */

Loading…
Cancel
Save