Commit f2b487db authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo
Browse files

perf hists browser: Fix possible memory leak



The options array saves strings for each popup menu item.  The number of
items can be vary according to the currently selected item.  So it can
leak some memory if it's exited from a small item.  Fix it by freeing
all items when loop terminates.

Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429687101-4360-4-git-send-email-namhyung@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent d8a0f800
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -1424,7 +1424,8 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
	struct hist_browser *browser = hist_browser__new(hists);
	struct hist_browser *browser = hist_browser__new(hists);
	struct branch_info *bi;
	struct branch_info *bi;
	struct pstack *fstack;
	struct pstack *fstack;
	char *options[16];
#define MAX_OPTIONS  16
	char *options[MAX_OPTIONS];
	int nr_options = 0;
	int nr_options = 0;
	int key = -1;
	int key = -1;
	char buf[64];
	char buf[64];
@@ -1691,7 +1692,8 @@ skip_annotation:
				"Switch to another data file in PWD") > 0)
				"Switch to another data file in PWD") > 0)
			switch_data = nr_options++;
			switch_data = nr_options++;
add_exit_option:
add_exit_option:
		options[nr_options++] = (char *)"Exit";
		if (asprintf(&options[nr_options], "Exit") > 0)
			nr_options++;
retry_popup_menu:
retry_popup_menu:
		choice = ui__popup_menu(nr_options, options);
		choice = ui__popup_menu(nr_options, options);


@@ -1812,7 +1814,7 @@ out_free_stack:
	pstack__delete(fstack);
	pstack__delete(fstack);
out:
out:
	hist_browser__delete(browser);
	hist_browser__delete(browser);
	free_popup_options(options, nr_options - 1);
	free_popup_options(options, MAX_OPTIONS);
	return key;
	return key;
}
}