cleanup, null checks. etc.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6673 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-12-11 21:31:57 +00:00
parent 21db9795d0
commit e46266fb4f
8 changed files with 28 additions and 18 deletions

View File

@ -536,7 +536,9 @@ SWITCH_DECLARE(void) switch_core_runtime_loop(int bg)
#ifdef WIN32 #ifdef WIN32
snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid()); snprintf(path, sizeof(path), "Global\\Freeswitch.%d", getpid());
shutdown_event = CreateEvent(NULL, FALSE, FALSE, path); shutdown_event = CreateEvent(NULL, FALSE, FALSE, path);
WaitForSingleObject(shutdown_event, INFINITE); if (shutdown_event) {
WaitForSingleObject(shutdown_event, INFINITE);
}
#else #else
runtime.running = 1; runtime.running = 1;
while (runtime.running) { while (runtime.running) {

View File

@ -145,9 +145,9 @@ SWITCH_DECLARE(void) switch_hash_this(switch_hash_index_t *hi, const void **key,
{ {
if (key) { if (key) {
*key = sqliteHashKey((HashElem *) hi); *key = sqliteHashKey((HashElem *) hi);
} if (klen) {
if (klen) { *klen = strlen((char *) *key) + 1;
*klen = strlen((char *) *key) + 1; }
} }
if (val) { if (val) {
*val = sqliteHashData((HashElem *) hi); *val = sqliteHashData((HashElem *) hi);

View File

@ -270,13 +270,13 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_
int x; int x;
for (x = 0; x < argc; x++) { for (x = 0; x < argc; x++) {
const char *val; const char *vval;
if ((val = switch_channel_get_variable(channel, argv[x]))) { if ((vval = switch_channel_get_variable(channel, argv[x]))) {
char *var = argv[x]; char *vvar = argv[x];
if (!strncasecmp(var, "nolocal:", 8)) { if (!strncasecmp(vvar, "nolocal:", 8)) {
var += 8; vvar += 8;
} }
switch_channel_set_variable(peer_channel, var, val); switch_channel_set_variable(peer_channel, vvar, vval);
} }
} }
} }

View File

@ -850,6 +850,7 @@ SWITCH_DECLARE(switch_xml_t) switch_event_xmlize(switch_event_t *event, const ch
ret = vasprintf(&data, fmt, ap); ret = vasprintf(&data, fmt, ap);
#else #else
data = (char *) malloc(2048); data = (char *) malloc(2048);
switch_assert(data);
ret = vsnprintf(data, 2048, fmt, ap); ret = vsnprintf(data, 2048, fmt, ap);
#endif #endif
va_end(ap); va_end(ap);

View 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) { while (apr_dir_read(&finfo, finfo_flags, module_dir_handle) == APR_SUCCESS) {
const char *fname = finfo.fname; const char *fname = finfo.fname;
const char *err;
if (finfo.filetype != APR_REG) { if (finfo.filetype != APR_REG) {
continue; continue;

View File

@ -80,7 +80,7 @@ SWITCH_DECLARE(uint32_t) switch_log_str2mask(const char *str)
switch_assert(p); switch_assert(p);
if ((argc = switch_separate_string(p, ',', argv, (sizeof(argv) / sizeof(argv[0]))))) { 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")) { if (!strcasecmp(argv[x], "all")) {
mask = 0xFF; mask = 0xFF;
break; 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)); len = (uint32_t) (strlen(extra_fmt) + strlen(date) + strlen(filep) + 32 + strlen(funcp) + strlen(fmt));
new_fmt = malloc(len + 1); 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); snprintf(new_fmt, len, extra_fmt, date, switch_log_level2str(level), filep, line, funcp, 128, fmt);
fmt = new_fmt; fmt = new_fmt;
} }

View File

@ -407,9 +407,10 @@ SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep)
{ {
switch_odbc_handle_t *handle = NULL; switch_odbc_handle_t *handle = NULL;
if (handlep) { if (!handlep) {
handle = *handlep; return;
} }
handle = *handlep;
if (handle) { if (handle) {
switch_odbc_handle_disconnect(handle); switch_odbc_handle_disconnect(handle);

View File

@ -45,7 +45,7 @@ SWITCH_DECLARE(char *) switch_find_end_paren(const char *s, char open, char clos
s++; s++;
} }
if (*s == open) { if (s && *s == open) {
depth++; depth++;
for (e = s + 1; e && *e; e++) { for (e = s + 1; e && *e; e++) {
if (*e == open) { if (*e == open) {
@ -266,11 +266,11 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to, const char *fr
} }
if (file) { if (file) {
const char *filename = switch_cut_path(file); const char *stipped_file = switch_cut_path(file);
const char *new_type; const char *new_type;
char *ext; char *ext;
if ((ext = strrchr(filename, '.'))) { if ((ext = strrchr(stipped_file, '.'))) {
ext++; ext++;
if ((new_type = switch_core_mime_ext2type(ext))) { if ((new_type = switch_core_mime_ext2type(ext))) {
mime_type = new_type; 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-Transfer-Encoding: base64\n"
"Content-Description: Sound attachment.\n" "Content-Description: Sound attachment.\n"
"Content-Disposition: attachment; filename=\"%s\"\n\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)) if (!write_buf(fd, buf))
return SWITCH_FALSE; 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) SWITCH_DECLARE(switch_bool_t) switch_ast2regex(char *pat, char *rbuf, size_t len)
{ {
char *p = pat; char *p = pat;
if (!pat) {
return SWITCH_FALSE;
}
memset(rbuf, 0, len); memset(rbuf, 0, len);
*(rbuf + strlen(rbuf)) = '^'; *(rbuf + strlen(rbuf)) = '^';
@ -1101,6 +1106,7 @@ SWITCH_DECLARE(char *) switch_string_replace(const char *string, const char *sea
char *dest, *tmp; char *dest, *tmp;
dest = (char *) malloc(sizeof(char)); dest = (char *) malloc(sizeof(char));
switch_assert(dest);
for (i = 0; i < string_len; i++) { for (i = 0; i < string_len; i++) {
if (switch_string_match(string + i, string_len - i, search, search_len) == SWITCH_STATUS_SUCCESS) { if (switch_string_match(string + i, string_len - i, search, search_len) == SWITCH_STATUS_SUCCESS) {