static void perf_top__prompt_symbol(struct perf_top *top, const char *msg)
 {
-       char *buf = malloc(0), *p;
+       char *buf = NULL, *p;
        struct hist_entry *syme = top->sym_filter_entry, *n, *found = NULL;
        struct hists *hists = evsel__hists(top->sym_evsel);
        struct rb_node *next;
        cond_init(&top->qe.cond);
 }
 
+static void exit_process_thread(struct perf_top *top)
+{
+       ordered_events__free(&top->qe.data[0]);
+       ordered_events__free(&top->qe.data[1]);
+       mutex_destroy(&top->qe.mutex);
+       cond_destroy(&top->qe.cond);
+}
+
 static int __cmd_top(struct perf_top *top)
 {
        struct record_opts *opts = &top->record_opts;
        cond_signal(&top->qe.cond);
        pthread_join(thread_process, NULL);
        perf_set_singlethreaded();
+       exit_process_thread(top);
        return ret;
 }