Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf db-export: Fix thread ref-counting

Thread ref-counting was not done for get_main_thread() meaning that
there was a thread__get() from machine__find_thread() that was not being
paired with thread__put(). Fix that.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1432906425-9911-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
427cde32 60fb7742

+10 -9
+10 -9
tools/perf/util/db-export.c
··· 234 234 static struct thread *get_main_thread(struct machine *machine, struct thread *thread) 235 235 { 236 236 if (thread->pid_ == thread->tid) 237 - return thread; 237 + return thread__get(thread); 238 238 239 239 if (thread->pid_ == -1) 240 240 return NULL; ··· 308 308 if (err) 309 309 return err; 310 310 311 - /* FIXME: check refcounting for get_main_thread, that calls machine__find_thread... */ 312 311 main_thread = get_main_thread(al->machine, thread); 313 312 if (main_thread) 314 313 comm = machine__thread_exec_comm(al->machine, main_thread); 315 314 316 315 err = db_export__thread(dbe, thread, al->machine, comm); 317 316 if (err) 318 - return err; 317 + goto out_put; 319 318 320 319 if (comm) { 321 320 err = db_export__comm(dbe, comm, main_thread); 322 321 if (err) 323 - return err; 322 + goto out_put; 324 323 es.comm_db_id = comm->db_id; 325 324 } 326 325 ··· 327 328 328 329 err = db_ids_from_al(dbe, al, &es.dso_db_id, &es.sym_db_id, &es.offset); 329 330 if (err) 330 - return err; 331 + goto out_put; 331 332 332 333 if ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) && 333 334 sample_addr_correlates_sym(&evsel->attr)) { ··· 337 338 err = db_ids_from_al(dbe, &addr_al, &es.addr_dso_db_id, 338 339 &es.addr_sym_db_id, &es.addr_offset); 339 340 if (err) 340 - return err; 341 + goto out_put; 341 342 if (dbe->crp) { 342 343 err = thread_stack__process(thread, comm, sample, al, 343 344 &addr_al, es.db_id, 344 345 dbe->crp); 345 346 if (err) 346 - return err; 347 + goto out_put; 347 348 } 348 349 } 349 350 350 351 if (dbe->export_sample) 351 - return dbe->export_sample(dbe, &es); 352 + err = dbe->export_sample(dbe, &es); 352 353 353 - return 0; 354 + out_put: 355 + thread__put(main_thread); 356 + return err; 354 357 } 355 358 356 359 static struct {