Skip to contentSkip to conversation

xentop crash fix

PATCH New John Levon 1 participant 1 message Oct 17, 2006

lore
Share & tools
lore

John Levon

author
#0 lore raw

PATCH 1/1 xentop crash fix

# HG changeset patch
# User [email protected]
# Date 1161091503 25200
# Node ID e11d992700d1fe4ad7e761ad8d383ad4049c40b9
# Parent 3c79fe20116bccea65a7d455590bea6331d27d6f
It's not correct to call endwin() if initscr() fails, and it crashes older libcurses implementations.

tools/xenstat/xentop/xentop.c +5 -3
@@ -189,6 +189,8 @@ int prompt_val_len = 0;
 int prompt_val_len = 0;
 void (*prompt_complete_func)(char *);
 
+static WINDOW *cwin;
+
 /*
  * Function definitions
  */
@@ -225,7 +227,7 @@ static void version(void)
 /* Clean up any open resources */
 static void cleanup(void)
 {
-	if(!isendwin())
+	if(cwin != NULL && !isendwin())
 		endwin();
 	if(prev_node != NULL)
 		xenstat_free_node(prev_node);
@@ -238,7 +240,7 @@ static void cleanup(void)
 /* Display the given message and gracefully exit */
 static void fail(const char *str)
 {
-	if(!isendwin())
+	if(cwin != NULL && !isendwin())
 		endwin();
 	fprintf(stderr, str);
 	exit(1);
@@ -1039,7 +1041,7 @@ int main(int argc, char **argv)
 
 	if (!batch) {
 		/* Begin curses stuff */
-		initscr();
+		cwin = initscr();
 		start_color();
 		cbreak();
 		noecho();