]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FSCORE-617
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 7 Jun 2010 21:47:35 +0000 (16:47 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 7 Jun 2010 21:47:35 +0000 (16:47 -0500)
src/include/switch_mprintf.h
src/include/switch_utils.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_directory/mod_directory.c
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_skinny/mod_skinny.c
src/switch_core_db.c
src/switch_core_sqldb.c

index af2396800da2f6dfca3f2409b7cf903411ee257b..cc5ed337d5617b9697cd4cb60bd6484286dce1f5 100644 (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:
index cea216a7e43396418c6a269d57f4519357a7328e..458538594963797316b6611bd619093c2063a4e2 100644 (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
 
index 2acd254c2d322cd116110efb524e1e34bae30079..990eb131e65d1459251ecbadc116692823cccd55 100644 (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;
                }
 
index 3a09216877520ab2e367af50aa154793ac01736d..d3389ab3b1f37eadd68bd18f755685339610ac7d 100644 (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) {
index 79475263839003a5b21a1cc660ba81ad11bd43ac..7ca52419f0767e23c095b9e97eb2e56a1856adfa 100755 (executable)
@@ -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);
                                        }
index aa3f07a959a3b8d002dd486e52986407ab07fdb9..27cf1cf005652e112033c1e6c7d9dcd8cede7393 100644 (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);
index 444bb038d02f376e978880459642ad81e5aae3ec..969992232a35935e095410f2933856b0e3e8e68a 100644 (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) {
index b3cfea9cfb6e3d26811d40ae6f831cc986d78b97..50ccbaf2254435f15b19005312e5ff7e9e1e6e43 100644 (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;
                        }
index 061c77fccc187e953fd9471c99963c35e1251e06..ee112d7a9b7161a1763dee6771f17e59db2b4ea9 100644 (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;