[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] xentop crash fix



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

Signed-off-by: John Levon <john.levon@xxxxxxx>

diff --git a/tools/xenstat/xentop/xentop.c b/tools/xenstat/xentop/xentop.c
--- a/tools/xenstat/xentop/xentop.c
+++ b/tools/xenstat/xentop/xentop.c
@@ -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();

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.