From: John Levon Subject: [PATCH] xentop crash fix Date: Tue, 17 Oct 2006 14:25:54 +0100 Message-ID: <20061017132554.GD7013@totally.trollied.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org # HG changeset patch # User john.levon@sun.com # 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 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();