From f5edd27d1d6e4cf625bf9180e2b9c1fc900c9d93 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 20 Apr 2009 18:26:22 +0000 Subject: [PATCH] corosync-cfgtool.c: handle strdup failure gracefully * tools/corosync-cfgtool.c (xstrdup): New function. (main): Use it in place of strdup. git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2100 fd59a12c-fef9-0310-b244-a6a79926bd2f --- tools/corosync-cfgtool.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/corosync-cfgtool.c b/tools/corosync-cfgtool.c index da026193..52e4f93c 100644 --- a/tools/corosync-cfgtool.c +++ b/tools/corosync-cfgtool.c @@ -245,6 +245,17 @@ static void usage_do (void) printf ("\t-H\tShutdown corosync cleanly on this node.\n"); } +static char * +xstrdup (char const *s) +{ + char *p = strdup (s); + if (p) + return (char *) p; + + printf ("exhausted virtual memory\n"); + exit (1); +} + int main (int argc, char *argv[]) { const char *options = "srl:u:v:k:a:hH"; int opt; @@ -267,11 +278,11 @@ int main (int argc, char *argv[]) { break; case 'l': service_load = 1; - service = strdup (optarg); + service = xstrdup (optarg); break; case 'u': service_unload = 1; - service = strdup (optarg); + service = xstrdup (optarg); break; case 'k': nodeid = atoi (optarg);