tools lib traceevent: Copy trace_clock and free it
The pevent->trace_clock should not be a direct pointer to what was given. It should be copied and freed. Note, valgrind pointed this out when a caller passed in a pointer that needed to be freed and it never was. Ideally, pevent should copy it (which this change does), and free the copy. It's up to the caller to free the clock string passed in. Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Link: http://lkml.kernel.org/r/20150324135922.695906738@goodmis.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
		
					parent
					
						
							
								deab6f55a2
							
						
					
				
			
			
				commit
				
					
						99ad1417db
					
				
			
		
					 2 changed files with 9 additions and 3 deletions
				
			
		| 
						 | 
					@ -321,9 +321,14 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock)
 | 
					int pevent_register_trace_clock(struct pevent *pevent, const char *trace_clock)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	pevent->trace_clock = trace_clock;
 | 
						pevent->trace_clock = strdup(trace_clock);
 | 
				
			||||||
 | 
						if (!pevent->trace_clock) {
 | 
				
			||||||
 | 
							errno = ENOMEM;
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct func_map {
 | 
					struct func_map {
 | 
				
			||||||
| 
						 | 
					@ -6352,6 +6357,7 @@ void pevent_free(struct pevent *pevent)
 | 
				
			||||||
		free_handler(handle);
 | 
							free_handler(handle);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						free(pevent->trace_clock);
 | 
				
			||||||
	free(pevent->events);
 | 
						free(pevent->events);
 | 
				
			||||||
	free(pevent->sort_events);
 | 
						free(pevent->sort_events);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -599,7 +599,7 @@ enum trace_flag_type {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
 | 
					int pevent_register_comm(struct pevent *pevent, const char *comm, int pid);
 | 
				
			||||||
void pevent_register_trace_clock(struct pevent *pevent, char *trace_clock);
 | 
					int pevent_register_trace_clock(struct pevent *pevent, const char *trace_clock);
 | 
				
			||||||
int pevent_register_function(struct pevent *pevent, char *name,
 | 
					int pevent_register_function(struct pevent *pevent, char *name,
 | 
				
			||||||
			     unsigned long long addr, char *mod);
 | 
								     unsigned long long addr, char *mod);
 | 
				
			||||||
int pevent_register_print_string(struct pevent *pevent, const char *fmt,
 | 
					int pevent_register_print_string(struct pevent *pevent, const char *fmt,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue