From df7b770ebb0d02f5f5c8ebe59090047f031d0013 Mon Sep 17 00:00:00 2001 From: mom040267 Date: Mon, 1 Dec 2014 17:54:38 +0000 Subject: [PATCH] minor fixes --- src/apps/relay/dbdrivers/dbd_sqlite.c | 2 +- src/apps/relay/mainrelay.c | 30 ++++++++++++--------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/apps/relay/dbdrivers/dbd_sqlite.c b/src/apps/relay/dbdrivers/dbd_sqlite.c index 957c9d4..0646bfa 100644 --- a/src/apps/relay/dbdrivers/dbd_sqlite.c +++ b/src/apps/relay/dbdrivers/dbd_sqlite.c @@ -126,7 +126,7 @@ static sqlite3 * get_sqlite_connection(void) { int rc = sqlite3_open(pud->userdb, &sqliteconnection); if(!sqliteconnection || (rc != SQLITE_OK)) { const char* errmsg = sqlite3_errmsg(sqliteconnection); - TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot open SQLite DB connection: <%s>, runtime error:\n %s\n (If your intention is to use a database for the TURN server, then\n check the TURN server process / file / DB directory permissions and\n re-start the TURN server)\n",pud->userdb,errmsg); + TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot open SQLite DB connection: <%s>, runtime error:\n %s\n (If your intention is to use an SQLite database for the TURN server, then\n check and fix, if necessary, the effective permissions of the TURN server\n process and of the DB directory and then re-start the TURN server)\n",pud->userdb,errmsg); if(sqliteconnection) { sqlite3_close(sqliteconnection); sqliteconnection=NULL; diff --git a/src/apps/relay/mainrelay.c b/src/apps/relay/mainrelay.c index 99e134a..c309351 100644 --- a/src/apps/relay/mainrelay.c +++ b/src/apps/relay/mainrelay.c @@ -2065,16 +2065,18 @@ int main(int argc, char **argv) static char some_buffer[65536]; -static pthread_mutex_t** mutex_buf = NULL; +//array larger than anything that OpenSSL may need: +static pthread_mutex_t mutex_buf[256]; +static int mutex_buf_initialized = 0; static void locking_function(int mode, int n, const char *file, int line) { UNUSED_ARG(file); UNUSED_ARG(line); - if(mutex_buf && (n < CRYPTO_num_locks()) && mutex_buf[n]) { + if(mutex_buf_initialized && (n < CRYPTO_num_locks())) { if (mode & CRYPTO_LOCK) - pthread_mutex_lock(mutex_buf[n]); + pthread_mutex_lock(&(mutex_buf[n])); else - pthread_mutex_unlock(mutex_buf[n]); + pthread_mutex_unlock(&(mutex_buf[n])); } } @@ -2100,14 +2102,12 @@ static int THREAD_setup(void) { some_buffer[0] = 0; - mutex_buf = (pthread_mutex_t**) turn_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t*)); - if (!mutex_buf) - return 0; for (i = 0; i < CRYPTO_num_locks(); i++) { - mutex_buf[i] = (pthread_mutex_t*) turn_malloc(sizeof(pthread_mutex_t)); - pthread_mutex_init(mutex_buf[i], NULL); + pthread_mutex_init(&(mutex_buf[i]), NULL); } + mutex_buf_initialized = 1; + #if OPENSSL_VERSION_NUMBER >= 0x10000000L CRYPTO_THREADID_set_callback(id_function); #else @@ -2127,7 +2127,7 @@ int THREAD_cleanup(void) { int i; - if (!mutex_buf) + if (!mutex_buf_initialized) return 0; #if OPENSSL_VERSION_NUMBER >= 0x10000000L @@ -2138,14 +2138,10 @@ int THREAD_cleanup(void) { CRYPTO_set_locking_callback(NULL); for (i = 0; i < CRYPTO_num_locks(); i++) { - if(mutex_buf[i]) { - pthread_mutex_destroy(mutex_buf[i]); - turn_free(mutex_buf[i],sizeof(pthread_mutex_t)); - mutex_buf[i] = NULL; - } + pthread_mutex_destroy(&(mutex_buf[i])); } - turn_free(mutex_buf,CRYPTO_num_locks() * sizeof(pthread_mutex_t*)); - mutex_buf = NULL; + + mutex_buf_initialized = 0; #endif