]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
cleanup, null checks. etc.
authorMichael Jerris <mike@jerris.com>
Tue, 11 Dec 2007 21:31:57 +0000 (21:31 +0000)
committerMichael Jerris <mike@jerris.com>
Tue, 11 Dec 2007 21:31:57 +0000 (21:31 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6673 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_core.c
src/switch_core_hash.c
src/switch_core_session.c
src/switch_event.c
src/switch_loadable_module.c
src/switch_log.c
src/switch_odbc.c
src/switch_utils.c

index 489ad3c31f37d1b2a08b835cb8eb380b54c4c33d..bbe0f85a3b150cd6d599674de9e8161f3750e908 100644 (file)
@@ -536,7 +536,9 @@ SWITCH_DECLARE(void) switch_core_runtime_loop(int bg)
 #ifdef WIN32
                snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
                shutdown_event = CreateEvent(NULL, FALSE, FALSE, path);
-               WaitForSingleObject(shutdown_event, INFINITE);
+               if (shutdown_event) {
+                       WaitForSingleObject(shutdown_event, INFINITE);
+               }
 #else
                runtime.running = 1;
                while (runtime.running) {
index 381499cbc31c1cbeefbd387bfca0796472af1ae4..38aafd7a717717693ea95c84ce90fa4c356fcce3 100644 (file)
@@ -145,9 +145,9 @@ SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t *hi, const void **key,
 {
        if (key) {
                *key = sqliteHashKey((HashElem *) hi);
-       }
-       if (klen) {
-               *klen = strlen((char *) *key) + 1;
+               if (klen) {
+                       *klen = strlen((char *) *key) + 1;
+               }
        }
        if (val) {
                *val = sqliteHashData((HashElem *) hi);
index 04264e9f925ac9a459cbab6689fdf7971de802ee..0783e0133b6f6298cdfeb298a408f8198fc4fe85 100644 (file)
@@ -270,13 +270,13 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_
                                        int x;
 
                                        for (x = 0; x < argc; x++) {
-                                               const char *val;
-                                               if ((val = switch_channel_get_variable(channel, argv[x]))) {
-                                                       char *var = argv[x];
-                                                       if (!strncasecmp(var, "nolocal:", 8)) {
-                                                               var += 8;
+                                               const char *vval;
+                                               if ((vval = switch_channel_get_variable(channel, argv[x]))) {
+                                                       char *vvar = argv[x];
+                                                       if (!strncasecmp(vvar, "nolocal:", 8)) {
+                                                               vvar += 8;
                                                        }
-                                                       switch_channel_set_variable(peer_channel, var, val);
+                                                       switch_channel_set_variable(peer_channel, vvar, vval);
                                                }
                                        }
                                }
index c897e085f42b7e8d44e1d0e43de4a11329ada7bd..b5c80936627f8512d17c7ee85b114e90b1f1f599 100644 (file)
@@ -850,6 +850,7 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
                ret = vasprintf(&data, fmt, ap);
 #else
                data = (char *) malloc(2048);
+               switch_assert(data);
                ret = vsnprintf(data, 2048, fmt, ap);
 #endif
                va_end(ap);
index 514f79f836cc619d52168ddfc23e044b7d0d9238..907353fbaeea688a5a55095f435af3fb06080780 100644 (file)
@@ -1030,7 +1030,6 @@ SWITCH_DECLARE(switch_status_t) switch_loadable_module_init()
 
                while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
                        const char *fname = finfo.fname;
-                       const char *err;
 
                        if (finfo.filetype != APR_REG) {
                                continue;
index 104c238d8640536becc988fdc71b57631af7feaf..89d98d7d0d2bd34f7cd45c4d6744e5027c1aa50a 100644 (file)
@@ -80,7 +80,7 @@ SWITCH_DECLARE(uint32_t) switch_log_str2mask(const char *str)
        switch_assert(p);
 
        if ((argc = switch_separate_string(p, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) {
-               for (x = 0; x < argc; x++) {
+               for (x = 0; x < argc && argv[x]; x++) {
                        if (!strcasecmp(argv[x], "all")) {
                                mask = 0xFF;
                                break;
@@ -221,6 +221,7 @@ SWITCH_DECLARE(void) switch_log_printf(switch_text_channel_t channel, const char
 
                len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
                new_fmt = malloc(len + 1);
+               switch_assert(new_fmt);
                snprintf(new_fmt, len, extra_fmt, date, switch_log_level2str(level), filep, line, funcp, 128, fmt);
                fmt = new_fmt;
        }
index 757bbce5ee8c5dad65f9ca15169190ad656185d7..a9d38b044500ddd2f6a8c9f34032a1cc034b3840 100644 (file)
@@ -407,9 +407,10 @@ SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
 {
        switch_odbc_handle_t *handle = NULL;
 
-       if (handlep) {
-               handle = *handlep;
+       if (!handlep) {
+               return;
        }
+       handle = *handlep;
 
        if (handle) {
                switch_odbc_handle_disconnect(handle);
index b5dd31a07f5dbf1c4a49b6fc21a862513eaa0f8d..e0f6c72189d06a536043c1201b96cf6891d23b19 100644 (file)
@@ -45,7 +45,7 @@ SWITCH_DECLARE(char *) switch_find_end_paren(const char *s, char open, char clos
                s++;
        }
 
-       if (*s == open) {
+       if (s && *s == open) {
                depth++;
                for (e = s + 1; e && *e; e++) {
                        if (*e == open) {
@@ -266,11 +266,11 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
         }
 
         if (file) {
-                       const char *filename = switch_cut_path(file);
+                       const char *stipped_file = switch_cut_path(file);
                        const char *new_type;
                        char *ext;
 
-                       if ((ext = strrchr(filename, '.'))) {
+                       if ((ext = strrchr(stipped_file, '.'))) {
                                ext++;
                                if ((new_type = switch_core_mime_ext2type(ext))) {
                                        mime_type = new_type;
@@ -283,7 +283,7 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
                                         "Content-Transfer-Encoding: base64\n"
                                         "Content-Description: Sound attachment.\n"
                                         "Content-Disposition: attachment; filename=\"%s\"\n\n",
-                                        bound, mime_type, filename, filename);
+                                        bound, mime_type, stipped_file, stipped_file);
             if (!write_buf(fd, buf))
                 return SWITCH_FALSE;
 
@@ -379,6 +379,11 @@ SWITCH_DECLARE(switch_bool_t) switch_is_lan_addr(const char *ip)
 SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len)
 {
        char *p = pat;
+
+       if (!pat) {
+               return SWITCH_FALSE;
+       }
+
        memset(rbuf, 0, len);
        
        *(rbuf + strlen(rbuf)) = '^';
@@ -1101,6 +1106,7 @@ SWITCH_DECLARE(char *) switch_string_replace(const char *string, const char *sea
        char *dest, *tmp;
 
        dest = (char *) malloc(sizeof(char));
+       switch_assert(dest);
 
        for (i = 0; i < string_len; i++) {
                if (switch_string_match(string + i, string_len - i, search, search_len) == SWITCH_STATUS_SUCCESS) {