aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parse-events.c38
-rw-r--r--trace-input.c18
-rw-r--r--trace-read.c2
-rw-r--r--trace-util.c3
4 files changed, 50 insertions, 11 deletions
diff --git a/parse-events.c b/parse-events.c
index 82477a7..9f88472 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -207,8 +207,7 @@ static int add_new_comm(struct pevent *pevent, char *comm, int pid)
207 * @pid: the pid to map the command line to 207 * @pid: the pid to map the command line to
208 * 208 *
209 * This adds a mapping to search for command line names with 209 * This adds a mapping to search for command line names with
210 * a given pid. Note, the comm that is given is stored and 210 * a given pid. The comm is duplicated.
211 * a duplicate is not made.
212 */ 211 */
213int pevent_register_comm(struct pevent *pevent, char *comm, int pid) 212int pevent_register_comm(struct pevent *pevent, char *comm, int pid)
214{ 213{
@@ -218,7 +217,7 @@ int pevent_register_comm(struct pevent *pevent, char *comm, int pid)
218 return add_new_comm(pevent, comm, pid); 217 return add_new_comm(pevent, comm, pid);
219 218
220 item = malloc_or_die(sizeof(*item)); 219 item = malloc_or_die(sizeof(*item));
221 item->comm = comm; 220 item->comm = strdup(comm);
222 item->pid = pid; 221 item->pid = pid;
223 item->next = pevent->cmdlist; 222 item->next = pevent->cmdlist;
224 223
@@ -356,7 +355,7 @@ const char *pevent_find_function(struct pevent *pevent, unsigned long long addr)
356 * @mod: the kernel module the function may be in (NULL for none) 355 * @mod: the kernel module the function may be in (NULL for none)
357 * 356 *
358 * This registers a function name with an address and module. 357 * This registers a function name with an address and module.
359 * The @func passed in is stored and a copy is not made. 358 * The @func passed in is duplicated.
360 */ 359 */
361int pevent_register_function(struct pevent *pevent, char *func, 360int pevent_register_function(struct pevent *pevent, char *func,
362 unsigned long long addr, char *mod) 361 unsigned long long addr, char *mod)
@@ -366,8 +365,11 @@ int pevent_register_function(struct pevent *pevent, char *func,
366 item = malloc_or_die(sizeof(*item)); 365 item = malloc_or_die(sizeof(*item));
367 366
368 item->next = pevent->funclist; 367 item->next = pevent->funclist;
369 item->func = func; 368 item->func = strdup(func);
370 item->mod = mod; 369 if (mod)
370 item->mod = strdup(mod);
371 else
372 item->mod = NULL;
371 item->addr = addr; 373 item->addr = addr;
372 374
373 pevent->funclist = item; 375 pevent->funclist = item;
@@ -476,7 +478,7 @@ find_printk(struct pevent *pevent, unsigned long long addr)
476 * @addr: the address the string was located at 478 * @addr: the address the string was located at
477 * 479 *
478 * This registers a string by the address it was stored in the kernel. 480 * This registers a string by the address it was stored in the kernel.
479 * The @fmt is used in storage and a duplicate is not made. 481 * The @fmt passed in is duplicated.
480 */ 482 */
481int pevent_register_print_string(struct pevent *pevent, char *fmt, 483int pevent_register_print_string(struct pevent *pevent, char *fmt,
482 unsigned long long addr) 484 unsigned long long addr)
@@ -487,7 +489,7 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt,
487 489
488 item->next = pevent->printklist; 490 item->next = pevent->printklist;
489 pevent->printklist = item; 491 pevent->printklist = item;
490 item->printk = fmt; 492 item->printk = strdup(fmt);
491 item->addr = addr; 493 item->addr = addr;
492 494
493 pevent->printk_count++; 495 pevent->printk_count++;
@@ -3799,9 +3801,23 @@ struct pevent *pevent_alloc(void)
3799 return pevent; 3801 return pevent;
3800} 3802}
3801 3803
3804static void free_format_fields(struct format_field *field)
3805{
3806 struct format_field *next;
3807
3808 while (field) {
3809 next = field->next;
3810 free(field->type);
3811 free(field->name);
3812 free(field);
3813 field = next;
3814 }
3815}
3816
3802static void free_formats(struct format *format) 3817static void free_formats(struct format *format)
3803{ 3818{
3804 /* IMPLEMENT ME */ 3819 free_format_fields(format->common_fields);
3820 free_format_fields(format->fields);
3805} 3821}
3806 3822
3807static void free_event(struct event_format *event) 3823static void free_event(struct event_format *event)
@@ -3813,6 +3829,8 @@ static void free_event(struct event_format *event)
3813 3829
3814 free(event->print_fmt.format); 3830 free(event->print_fmt.format);
3815 free_args(event->print_fmt.args); 3831 free_args(event->print_fmt.args);
3832
3833 free(event);
3816} 3834}
3817 3835
3818/** 3836/**
@@ -3876,4 +3894,6 @@ void pevent_free(struct pevent *pevent)
3876 3894
3877 free_event(event); 3895 free_event(event);
3878 } 3896 }
3897
3898 free(pevent);
3879} 3899}
diff --git a/trace-input.c b/trace-input.c
index db48c91..72a604e 100644
--- a/trace-input.c
+++ b/trace-input.c
@@ -518,6 +518,13 @@ static void free_page(struct tracecmd_input *handle, int cpu)
518 handle->cpu_data[cpu].page = NULL; 518 handle->cpu_data[cpu].page = NULL;
519} 519}
520 520
521static void free_read_page(struct tracecmd_input *handle, int cpu)
522{
523 free_page(handle, cpu);
524 if (handle->read_page)
525 free(handle->cpu_data[cpu].read_page);
526}
527
521/* 528/*
522 * Page is mapped, now read in the page header info. 529 * Page is mapped, now read in the page header info.
523 */ 530 */
@@ -1485,8 +1492,17 @@ struct tracecmd_input *tracecmd_open(const char *file)
1485 1492
1486void tracecmd_close(struct tracecmd_input *handle) 1493void tracecmd_close(struct tracecmd_input *handle)
1487{ 1494{
1488 /* TODO FREE EVERYTHING!!! %%%% MEMORY LEAK!!! %%%% */ 1495 int cpu;
1496
1497 if (!handle)
1498 return;
1499
1500 for (cpu = 0; cpu < handle->cpus; cpu++)
1501 free_read_page(handle, cpu);
1502 free(handle->cpu_data);
1503
1489 close(handle->fd); 1504 close(handle->fd);
1505 pevent_free(handle->pevent);
1490 free(handle); 1506 free(handle);
1491} 1507}
1492 1508
diff --git a/trace-read.c b/trace-read.c
index 175d0d3..f2c7de2 100644
--- a/trace-read.c
+++ b/trace-read.c
@@ -412,7 +412,7 @@ void trace_report (int argc, char **argv)
412 412
413 read_data_info(handle); 413 read_data_info(handle);
414 414
415 pevent_free(pevent); 415 tracecmd_close(handle);
416 416
417 return; 417 return;
418} 418}
diff --git a/trace-util.c b/trace-util.c
index c3d89c6..d5be6ed 100644
--- a/trace-util.c
+++ b/trace-util.c
@@ -89,6 +89,7 @@ void parse_cmdlines(struct pevent *pevent,
89 sscanf(line, "%d %as", &pid, 89 sscanf(line, "%d %as", &pid,
90 (float *)(void *)&comm); /* workaround gcc warning */ 90 (float *)(void *)&comm); /* workaround gcc warning */
91 pevent_register_comm(pevent, comm, pid); 91 pevent_register_comm(pevent, comm, pid);
92 free(comm);
92 line = strtok_r(NULL, "\n", &next); 93 line = strtok_r(NULL, "\n", &next);
93 } 94 }
94} 95}
@@ -121,6 +122,8 @@ void parse_proc_kallsyms(struct pevent *pevent,
121 mod[strlen(mod) - 1] = 0; 122 mod[strlen(mod) - 1] = 0;
122 123
123 pevent_register_function(pevent, func, addr, mod); 124 pevent_register_function(pevent, func, addr, mod);
125 free(func);
126 free(mod);
124 127
125 line = strtok_r(NULL, "\n", &next); 128 line = strtok_r(NULL, "\n", &next);
126 } 129 }