[10/28] fix segfault when the default window is not the clock

Message ID 1308256197-29155-10-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 16, 2011, 8:29 p.m.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 clocks.c     |    2 +-
 powerdebug.c |   11 ++++-------
 2 files changed, 5 insertions(+), 8 deletions(-)

Patch

diff --git a/clocks.c b/clocks.c
index d08c926..ecc72ea 100644
--- a/clocks.c
+++ b/clocks.c
@@ -255,7 +255,7 @@  int read_and_print_clock_info(int verbose, int hrow, int selected)
 		read_clock_info(clk_dir_path);
 	}
 
-	if (!clocks_info->num_children) {
+	if (!clocks_info || !clocks_info->num_children) {
 		fprintf(stderr, "powerdebug: No clocks found. Exiting..\n");
 		exit(1);
 	}
diff --git a/powerdebug.c b/powerdebug.c
index 5fe07de..94dd31a 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -251,19 +251,18 @@  int mainloop(struct powerdebug_options *options,
 
 		create_windows(options->selectedwindow);
 		show_header(options->selectedwindow);
+		create_selectedwindow(options->selectedwindow);
 
-		if (options->regulators || options->selectedwindow == REGULATOR) {
+		if (options->selectedwindow == REGULATOR) {
 			regulator_read_info(reg_info, nr_reg);
-			create_selectedwindow(options->selectedwindow);
 			show_regulator_info(reg_info, nr_reg,
 					    options->verbose);
 		}
 
-		if (options->clocks || options->selectedwindow == CLOCK) {
+		if (options->selectedwindow == CLOCK) {
 
 			int hrow;
 
-			create_selectedwindow(options->selectedwindow);
 			if (!findparent_ncurses) {
 				int command = 0;
 
@@ -282,10 +281,8 @@  int mainloop(struct powerdebug_options *options,
 						       enter_hit);
 		}
 
-		if (options->sensors || options->selectedwindow == SENSOR) {
-			create_selectedwindow(options->selectedwindow);
+		if (options->selectedwindow == SENSOR)
 			print_sensor_header();
-		}
 
 		FD_ZERO(&readfds);
 		FD_SET(0, &readfds);