FSCORE-617

This commit is contained in:
Anthony Minessale 2010-06-07 16:47:35 -05:00
parent c9e0a41090
commit bc6334a610
9 changed files with 29 additions and 20 deletions

View File

@ -22,7 +22,7 @@ SWITCH_BEGIN_EXTERN_C
* options that are useful for constructing SQL statements.
*
* The strings returned by this routine should be freed by calling
* switch_core_db_free().
* free().
*
* All of the usual printf formatting options apply. In addition, there
* is a "%q" option. %q works like %s in that it substitutes a null-terminated
@ -37,9 +37,9 @@ SWITCH_BEGIN_EXTERN_C
*
* We can use this text in an SQL statement as follows:
*
* char *z = switch_core_db_mprintf("INSERT INTO TABLES('%q')", zText);
* char *z = switch_mprintf("INSERT INTO TABLES('%q')", zText);
* switch_core_db_exec(db, z, callback1, 0, 0);
* switch_core_db_free(z);
* free(z);
*
* Because the %q format string is used, the '\'' character in zText
* is escaped and the SQL generated is as follows:

View File

@ -653,14 +653,17 @@ SWITCH_DECLARE(int) switch_split_user_domain(char *in, char **user, char **domai
/* malloc or DIE macros */
#ifdef NDEBUG
#define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
#define switch_zmalloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), memset(ptr, 0, len))
#define switch_zmalloc(ptr, len) (void)( (!!(ptr = calloc(1, (len)))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr)
#define switch_strdup(ptr, s) (void)( (!!(ptr = strdup(s))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr)
#else
#if (_MSC_VER >= 1500) // VC9+
#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr);__analysis_assume( ptr )
#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len));__analysis_assume( ptr )
#define switch_zmalloc(ptr, len) (void)(assert((ptr = calloc(1, (len)))),ptr);__analysis_assume( ptr )
#define switch_strdup(ptr, s) (void)(assert(((ptr) = _strdup(s)((len)))),ptr);__analysis_assume( ptr )
#else
#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr)
#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len))
#define switch_zmalloc(ptr, len) (void)(assert((ptr = calloc(1, (len)))),ptr)
#define switch_strdup(ptr, s) (void)(assert(((ptr) = strdup((s)))),ptr)
#endif
#endif

View File

@ -3500,7 +3500,7 @@ SWITCH_STANDARD_API(show_function)
if (errmsg) {
stream->write_function(stream, "-ERR SQL Error [%s]\n", errmsg);
switch_core_db_free(errmsg);
free(errmsg);
errmsg = NULL;
} else if (help) {
if (holder.count == 0)
@ -3513,7 +3513,7 @@ SWITCH_STANDARD_API(show_function)
if (errmsg) {
stream->write_function(stream, "-ERR SQL Error [%s]\n", errmsg);
switch_core_db_free(errmsg);
free(errmsg);
errmsg = NULL;
}

View File

@ -295,7 +295,7 @@ static switch_bool_t directory_execute_sql_callback(switch_mutex_t *mutex, char
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
free(errmsg);
switch_core_db_free(errmsg);
}
if (db) {

View File

@ -379,7 +379,7 @@ SWITCH_STANDARD_APP(eavesdrop_function)
switch_cache_db_release_db_handle(&db);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error: %s\n", errmsg);
switch_core_db_free(errmsg);
free(errmsg);
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_failed"))) {
switch_ivr_play_file(session, NULL, file, NULL);
}

View File

@ -317,7 +317,7 @@ static switch_bool_t mdl_execute_sql_callback(mdl_profile_t *profile,
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
free(errmsg);
switch_core_db_free(errmsg);
}
if (db) {
@ -2730,7 +2730,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q';", from, to))) {
mdl_execute_sql(profile, sql, profile->mutex);
switch_core_db_free(sql);
free(sql);
}
break;
@ -2743,12 +2743,12 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
switch_mutex_lock(profile->mutex);
if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q'", from, to))) {
mdl_execute_sql(profile, sql, NULL);
switch_core_db_free(sql);
free(sql);
}
if ((sql = switch_mprintf("insert into jabber_subscriptions values('%q','%q','%q','%q');\n",
switch_str_nil(from), switch_str_nil(to), switch_str_nil(msg), switch_str_nil(subject)))) {
mdl_execute_sql(profile, sql, NULL);
switch_core_db_free(sql);
free(sql);
}
switch_mutex_unlock(profile->mutex);
if (is_special(to)) {
@ -2796,7 +2796,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
mdl_execute_sql(profile, sql, profile->mutex);
switch_core_db_free(sql);
free(sql);
}
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
@ -2831,7 +2831,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
mdl_execute_sql(profile, sql, profile->mutex);
switch_core_db_free(sql);
free(sql);
}
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);

View File

@ -329,7 +329,7 @@ switch_bool_t skinny_execute_sql_callback(skinny_profile_t *profile,
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
free(errmsg);
switch_core_db_free(errmsg);
}
if (db) {

View File

@ -93,7 +93,7 @@ SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db, const char *sql, s
ret = sqlite3_exec(db, sql, callback, data, &err);
if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
if (sane > 1) {
switch_safe_free(err);
switch_core_db_free(err);
switch_yield(100000);
continue;
}

View File

@ -374,6 +374,7 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t
{
switch_status_t status = SWITCH_STATUS_FALSE;
char *errmsg = NULL;
char *tmp = NULL;
if (dbh->io_mutex) {
switch_mutex_lock(dbh->io_mutex);
@ -395,6 +396,11 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t
case SCDB_TYPE_CORE_DB:
{
status = switch_core_db_exec(dbh->native_handle.core_db_dbh, sql, NULL, NULL, &errmsg);
if (errmsg) {
switch_strdup(tmp, errmsg);
switch_core_db_free(errmsg);
errmsg = tmp;
}
}
break;
}
@ -721,7 +727,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cach
if (errmsg) {
dbh->last_used = switch_epoch_time_now(NULL) - (SQL_CACHE_TIMEOUT * 2);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
free(errmsg);
switch_core_db_free(errmsg);
}
}
break;
@ -874,7 +880,7 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
len += newlen;
}
switch_core_db_free(sql);
free(sql);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "SQL thread ending\n");
break;