[Freeswitch-svn] [commit] r8421 - freeswitch/trunk/src

Freeswitch SVN mikej at freeswitch.org
Thu May 15 17:05:33 EDT 2008


Author: mikej
Date: Thu May 15 17:05:32 2008
New Revision: 8421

Modified:
   freeswitch/trunk/src/switch.c

Log:
handle malloc failures.  Found by Klockwork (www.klocwork.com)

Modified: freeswitch/trunk/src/switch.c
==============================================================================
--- freeswitch/trunk/src/switch.c	(original)
+++ freeswitch/trunk/src/switch.c	Thu May 15 17:05:32 2008
@@ -404,6 +404,10 @@
 			x++;
 			if (argv[x] && strlen(argv[x])) {
 				SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(strlen(argv[x]) + 1);
+				if (!SWITCH_GLOBAL_dirs.conf_dir) {
+					fprintf(stderr, "Allocation error\n");
+					return 255;
+				}
 				strcpy(SWITCH_GLOBAL_dirs.conf_dir, argv[x]);
 				alt_dirs++;
 			} else {
@@ -417,6 +421,10 @@
 			x++;
 			if (argv[x] && strlen(argv[x])) {
 				SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(strlen(argv[x]) + 1);
+				if (!SWITCH_GLOBAL_dirs.log_dir) {
+					fprintf(stderr, "Allocation error\n");
+					return 255;
+				}
 				strcpy(SWITCH_GLOBAL_dirs.log_dir, argv[x]);
 				alt_dirs++;
 			} else {
@@ -430,6 +438,10 @@
 			x++;
 			if (argv[x] && strlen(argv[x])) {
 				SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(strlen(argv[x]) + 1);
+				if (!SWITCH_GLOBAL_dirs.db_dir) {
+					fprintf(stderr, "Allocation error\n");
+					return 255;
+				}
 				strcpy(SWITCH_GLOBAL_dirs.db_dir, argv[x]);
 				alt_dirs++;
 			} else {
@@ -443,6 +455,10 @@
 			x++;
 			if (argv[x] && strlen(argv[x])) {
 				SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(strlen(argv[x]) + 1);
+				if (!SWITCH_GLOBAL_dirs.script_dir) {
+					fprintf(stderr, "Allocation error\n");
+					return 255;
+				}
 				strcpy(SWITCH_GLOBAL_dirs.script_dir, argv[x]);
 			} else {
 				fprintf(stderr, "When using -scripts you must specify a scripts directory\n");



More information about the Freeswitch-svn mailing list