]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
handle malloc failures. Found by Klockwork (www.klocwork.com)
authorMichael Jerris <mike@jerris.com>
Thu, 15 May 2008 21:05:32 +0000 (21:05 +0000)
committerMichael Jerris <mike@jerris.com>
Thu, 15 May 2008 21:05:32 +0000 (21:05 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8421 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch.c

index 534f87912607d0d7970ad43a33607189e1107df8..373db0065b99d956348f93e1bb3fc436ce8cfd47 100644 (file)
@@ -404,6 +404,10 @@ int main(int argc, char *argv[])
                        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 @@ int main(int argc, char *argv[])
                        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 @@ int main(int argc, char *argv[])
                        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 @@ int main(int argc, char *argv[])
                        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");