Skip to content

Commit

Permalink
LOG: copy the function/filename for dynamic callsites
Browse files Browse the repository at this point in the history
callsites originate from the assumption that the function/filename/format
are all statically allocated. When moving to dynamic callsite we kept
this assumption. But people are now passing in function/file names that
later get free'd. So we need to make sure that they stay persistant by
allocating them ourselves.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
  • Loading branch information
asalkeld committed Mar 20, 2013
1 parent ffdc2d5 commit 1c9104e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/log_dcs.c
Expand Up @@ -70,9 +70,9 @@ _log_dcs_new_cs(const char *function,
assert(rc == 0);
assert(cs != NULL);

cs->function = function;
cs->filename = filename;
cs->format = format;
cs->function = strdup(function);
cs->filename = strdup(filename);
cs->format = strdup(format);
cs->priority = priority;
cs->lineno = lineno;
cs->tags = tags;
Expand Down Expand Up @@ -180,6 +180,7 @@ qb_log_dcs_fini(void)
struct callsite_list *csl;
int32_t i;
int32_t rc;
struct qb_log_callsite *cs = NULL;
int32_t cnt = qb_array_num_bins_get(lookup_arr);
cnt *= qb_array_elems_per_bin_get(lookup_arr);

Expand All @@ -195,6 +196,14 @@ qb_log_dcs_fini(void)
}
}

for (i = 0; i < callsite_arr_next; i++) {
rc = qb_array_index(callsite_arr, i, (void **)&cs);
if (rc == 0 && cs){
free((char*)cs->function);
free((char*)cs->filename);
free((char*)cs->format);
}
}

qb_array_free(lookup_arr);
qb_array_free(callsite_arr);
Expand Down

0 comments on commit 1c9104e

Please sign in to comment.