Skip to content

Commit

Permalink
Last few mallocs / frees.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasnoble committed Apr 7, 2016
1 parent bdf80ac commit b29d8cf
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
2 changes: 2 additions & 0 deletions include/grpc/support/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#ifndef GRPC_SUPPORT_STRING_UTIL_H
#define GRPC_SUPPORT_STRING_UTIL_H

#include <grpc/support/port_platform.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
1 change: 1 addition & 0 deletions src/core/lib/support/log_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void gpr_log(const char *file, int line, gpr_log_severity severity,
}
va_end(args);
gpr_log_message(file, line, severity, message);
/* message has been allocated by vasprintf above, and needs free */
free(message);
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/tsi/fake_transport_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <stdlib.h>
#include <string.h>

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/useful.h>
Expand Down Expand Up @@ -137,7 +138,7 @@ static int tsi_fake_frame_ensure_size(tsi_fake_frame *frame) {
frame->data = gpr_malloc(frame->allocated_size);
if (frame->data == NULL) return 0;
} else if (frame->size > frame->allocated_size) {
unsigned char *new_data = realloc(frame->data, frame->size);
unsigned char *new_data = gpr_realloc(frame->data, frame->size);
if (new_data == NULL) {
gpr_free(frame->data);
frame->data = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/core/lib/tsi/ssl_transport_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <arpa/inet.h>
#endif

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
Expand Down
24 changes: 7 additions & 17 deletions src/core/lib/tsi/transport_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,16 @@

#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>

/* --- Tracing. --- */

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) {
Expand Down Expand Up @@ -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. */
}
Expand All @@ -242,7 +232,7 @@ tsi_result tsi_construct_allocated_string_peer_property(
if (name != NULL) property->name = gpr_strdup(name);
if (value_length > 0) {
property->value.data = gpr_malloc(value_length);
memset(value.data, 0, value_length);
memset(property->value.data, 0, value_length);
property->value.length = value_length;
}
return TSI_OK;
Expand Down

0 comments on commit b29d8cf

Please sign in to comment.