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

encoder: opentelemetry: assorted fixes #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cprof_encode_opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,7 @@ static int pack_cprof_scope_profiles(
result = pack_cprof_instrumentation_scope(&otlp_scope_profiles->scope, input_instance->scope);

if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) {
destroy_scope_profiles(otlp_scope_profiles);
return result;
}
}
Expand Down Expand Up @@ -2246,6 +2247,7 @@ static int pack_cprof_resource_profiles(
result = pack_cprof_resource(&otlp_resource_profiles->resource, input_instance->resource);

if (result != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) {
destroy_resource_profiles(otlp_resource_profiles);
return result;
}

Expand Down
17 changes: 13 additions & 4 deletions src/cprof_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void cprof_profile_destroy(struct cprof_profile *instance)

size_t cprof_profile_string_add(struct cprof_profile *profile, char *str, int str_len)
{
int alloc_size = 64;
const int alloc_size = 64;
size_t id;
size_t new_size;

Expand All @@ -239,28 +239,37 @@ size_t cprof_profile_string_add(struct cprof_profile *profile, char *str, int st
str_len = strlen(str);
}

if (!profile->string_table && str_len > 0) {
profile->string_table = malloc(alloc_size * sizeof(cfl_sds_t));
if (!profile->string_table) {
if (profile->string_table == NULL) {
profile->string_table = calloc(alloc_size, sizeof(cfl_sds_t));

if (profile->string_table == NULL) {
return -1;
}

profile->string_table_size = alloc_size;
profile->string_table_count = 0;
}

if (profile->string_table_count == 0 && str_len > 0) {
/* string_table[0] must always be "" */
profile->string_table[0] = cfl_sds_create_len("", 0);

if (!profile->string_table[0]) {
return -1;
}

profile->string_table_count = 1;
}

/* check there is enough room for a new entry */
if (profile->string_table_count >= profile->string_table_size) {
new_size = profile->string_table_size + alloc_size;
profile->string_table = realloc(profile->string_table, new_size * sizeof(cfl_sds_t));

if (!profile->string_table) {
return -1;
}

profile->string_table_size = alloc_size;
}

Expand Down
Loading