Merge pull request #14167 from ZhouyihaiDing/v1.9.x_php_call_leak

Backport PR #14155 - #14161 into 1.9.x
pull/14185/head
Stanley Cheung 7 years ago committed by GitHub
commit d782314d7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/php/ext/grpc/call.c
  2. 11
      src/php/ext/grpc/call_credentials.c
  3. 6
      src/php/ext/grpc/channel_credentials.c

@ -99,6 +99,7 @@ zval *grpc_parse_metadata_array(grpc_metadata_array
1 TSRMLS_CC);
efree(str_key);
efree(str_val);
PHP_GRPC_FREE_STD_ZVAL(array);
return NULL;
}
php_grpc_add_next_index_stringl(data, str_val,
@ -127,10 +128,12 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) {
HashTable *inner_array_hash;
zval *value;
zval *inner_array;
grpc_metadata_array_init(metadata);
metadata->count = 0;
metadata->metadata = NULL;
if (Z_TYPE_P(array) != IS_ARRAY) {
return false;
}
grpc_metadata_array_init(metadata);
array_hash = Z_ARRVAL_P(array);
char *key;
@ -538,7 +541,9 @@ cleanup:
*/
PHP_METHOD(Call, getPeer) {
wrapped_grpc_call *call = Z_WRAPPED_GRPC_CALL_P(getThis());
PHP_GRPC_RETURN_STRING(grpc_call_get_peer(call->wrapped), 1);
char *peer = grpc_call_get_peer(call->wrapped);
PHP_GRPC_RETVAL_STRING(peer, 1);
gpr_free(peer);
}
/**

@ -120,6 +120,8 @@ PHP_METHOD(CallCredentials, createFromPlugin) {
fci->params, fci->param_count) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"createFromPlugin expects 1 callback", 1 TSRMLS_CC);
free(fci);
free(fci_cache);
return;
}
@ -183,15 +185,17 @@ int plugin_get_metadata(
*status = GRPC_STATUS_OK;
*error_details = NULL;
bool should_return = false;
grpc_metadata_array metadata;
if (retval == NULL || Z_TYPE_P(retval) != IS_ARRAY) {
*status = GRPC_STATUS_INVALID_ARGUMENT;
return true; // Synchronous return.
should_return = true; // Synchronous return.
}
if (!create_metadata_array(retval, &metadata)) {
*status = GRPC_STATUS_INVALID_ARGUMENT;
return true; // Synchronous return.
should_return = true; // Synchronous return.
grpc_php_metadata_array_destroy_including_entries(&metadata);
}
if (retval != NULL) {
@ -204,6 +208,9 @@ int plugin_get_metadata(
PHP_GRPC_FREE_STD_ZVAL(retval);
#endif
}
if (should_return) {
return true;
}
if (metadata.count > GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX) {
*status = GRPC_STATUS_INTERNAL;

@ -57,6 +57,10 @@ static grpc_ssl_roots_override_result get_ssl_roots_override(
/* Frees and destroys an instance of wrapped_grpc_channel_credentials */
PHP_GRPC_FREE_WRAPPED_FUNC_START(wrapped_grpc_channel_credentials)
if (p->hashstr != NULL) {
free(p->hashstr);
p->hashstr = NULL;
}
if (p->wrapped != NULL) {
grpc_channel_credentials_release(p->wrapped);
p->wrapped = NULL;
@ -153,7 +157,7 @@ PHP_METHOD(ChannelCredentials, createSsl) {
}
php_grpc_int hashkey_len = root_certs_length + cert_chain_length;
char *hashkey = emalloc(hashkey_len);
char *hashkey = emalloc(hashkey_len + 1);
if (root_certs_length > 0) {
strcpy(hashkey, pem_root_certs);
}

Loading…
Cancel
Save