From e46266fb4f691d15dbe3a2f516ba9be62f155759 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Tue, 11 Dec 2007 21:31:57 +0000 Subject: [PATCH] cleanup, null checks. etc. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6673 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_core.c | 4 +++- src/switch_core_hash.c | 6 +++--- src/switch_core_session.c | 12 ++++++------ src/switch_event.c | 1 + src/switch_loadable_module.c | 1 - src/switch_log.c | 3 ++- src/switch_odbc.c | 5 +++-- src/switch_utils.c | 14 ++++++++++---- 8 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/switch_core.c b/src/switch_core.c index 489ad3c31f..bbe0f85a3b 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -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) { diff --git a/src/switch_core_hash.c b/src/switch_core_hash.c index 381499cbc3..38aafd7a71 100644 --- a/src/switch_core_hash.c +++ b/src/switch_core_hash.c @@ -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); diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 04264e9f92..0783e0133b 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -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); } } } diff --git a/src/switch_event.c b/src/switch_event.c index c897e085f4..b5c8093662 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -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); diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 514f79f836..907353fbae 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -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; diff --git a/src/switch_log.c b/src/switch_log.c index 104c238d86..89d98d7d0d 100644 --- a/src/switch_log.c +++ b/src/switch_log.c @@ -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; } diff --git a/src/switch_odbc.c b/src/switch_odbc.c index 757bbce5ee..a9d38b0445 100644 --- a/src/switch_odbc.c +++ b/src/switch_odbc.c @@ -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); diff --git a/src/switch_utils.c b/src/switch_utils.c index b5dd31a07f..e0f6c72189 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -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) {