Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a PHP memory leak with SSL root certificates #12706

Merged
merged 1 commit into from Dec 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/php/ext/grpc/channel_credentials.c
Expand Up @@ -35,6 +35,7 @@
#include <zend_hash.h>

#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>

Expand All @@ -46,10 +47,11 @@ static char *default_pem_root_certs = NULL;

static grpc_ssl_roots_override_result get_ssl_roots_override(
char **pem_root_certs) {
*pem_root_certs = default_pem_root_certs;
if (default_pem_root_certs == NULL) {
if (!default_pem_root_certs) {
*pem_root_certs = NULL;
return GRPC_SSL_ROOTS_OVERRIDE_FAIL;
}
*pem_root_certs = gpr_strdup(default_pem_root_certs);
return GRPC_SSL_ROOTS_OVERRIDE_OK;
}

Expand Down Expand Up @@ -101,7 +103,7 @@ PHP_METHOD(ChannelCredentials, setDefaultRootsPem) {
"setDefaultRootsPem expects 1 string", 1 TSRMLS_CC);
return;
}
default_pem_root_certs = gpr_malloc((pem_roots_length + 1) * sizeof(char));
default_pem_root_certs = gpr_realloc(default_pem_root_certs, (pem_roots_length + 1) * sizeof(char));
memcpy(default_pem_root_certs, pem_roots, pem_roots_length + 1);
}

Expand Down