diff options
author | David Garcia Quintas <dgq@google.com> | 2016-04-15 14:40:08 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-04-15 14:40:08 -0700 |
commit | ff71c38be9bf8d8527a6a44655f100b86564f886 (patch) | |
tree | 8cd55f9a769a37a2e8cd78ae95f7a819b823a724 /src/core/lib/tsi/transport_security.c | |
parent | 2196c7e253c2932473c9909bdb58b4931b5c677f (diff) | |
parent | ec138dd3cb2f592f2333a12f70282fd861a4e8f2 (diff) |
Merge branch 'master' of github.com:grpc/grpc into ip_parse_refactor
Diffstat (limited to 'src/core/lib/tsi/transport_security.c')
-rw-r--r-- | src/core/lib/tsi/transport_security.c | 38 |
1 files changed, 11 insertions, 27 deletions
diff --git a/src/core/lib/tsi/transport_security.c b/src/core/lib/tsi/transport_security.c index 861fc791bc..830cf09584 100644 --- a/src/core/lib/tsi/transport_security.c +++ b/src/core/lib/tsi/transport_security.c @@ -33,6 +33,9 @@ #include "src/core/lib/tsi/transport_security.h" +#include <grpc/support/alloc.h> +#include <grpc/support/string_util.h> + #include <stdlib.h> #include <string.h> @@ -40,19 +43,6 @@ int tsi_tracing_enabled = 0; -/* --- Utils. --- */ - -char *tsi_strdup(const char *src) { - char *dst; - size_t len; - if (!src) return NULL; - len = strlen(src) + 1; - dst = malloc(len); - if (!dst) return NULL; - memcpy(dst, src, len); - return dst; -} - /* --- tsi_result common implementation. --- */ const char *tsi_result_to_string(tsi_result result) { @@ -214,15 +204,15 @@ static void tsi_peer_destroy_list_property(tsi_peer_property *children, for (i = 0; i < child_count; i++) { tsi_peer_property_destruct(&children[i]); } - free(children); + gpr_free(children); } void tsi_peer_property_destruct(tsi_peer_property *property) { if (property->name != NULL) { - free(property->name); + gpr_free(property->name); } if (property->value.data != NULL) { - free(property->value.data); + gpr_free(property->value.data); } *property = tsi_init_peer_property(); /* Reset everything to 0. */ } @@ -239,16 +229,10 @@ void tsi_peer_destruct(tsi_peer *self) { tsi_result tsi_construct_allocated_string_peer_property( const char *name, size_t value_length, tsi_peer_property *property) { *property = tsi_init_peer_property(); - if (name != NULL) { - property->name = tsi_strdup(name); - if (property->name == NULL) return TSI_OUT_OF_RESOURCES; - } + if (name != NULL) property->name = gpr_strdup(name); if (value_length > 0) { - property->value.data = calloc(1, value_length); - if (property->value.data == NULL) { - tsi_peer_property_destruct(property); - return TSI_OUT_OF_RESOURCES; - } + property->value.data = gpr_malloc(value_length); + memset(property->value.data, 0, value_length); property->value.length = value_length; } return TSI_OK; @@ -276,8 +260,8 @@ tsi_result tsi_construct_string_peer_property(const char *name, tsi_result tsi_construct_peer(size_t property_count, tsi_peer *peer) { memset(peer, 0, sizeof(tsi_peer)); if (property_count > 0) { - peer->properties = calloc(property_count, sizeof(tsi_peer_property)); - if (peer->properties == NULL) return TSI_OUT_OF_RESOURCES; + peer->properties = gpr_malloc(property_count * sizeof(tsi_peer_property)); + memset(peer->properties, 0, property_count * sizeof(tsi_peer_property)); peer->property_count = property_count; } return TSI_OK; |