diff --git a/pjlib/src/pj/log.c b/pjlib/src/pj/log.c index a2951d6dd..73b4d45b7 100644 --- a/pjlib/src/pj/log.c +++ b/pjlib/src/pj/log.c @@ -151,14 +151,17 @@ pj_status_t pj_log_init(void) if (thread_suspended_tls_id == -1) { pj_status_t status; status = pj_thread_local_alloc(&thread_suspended_tls_id); - if (status != PJ_SUCCESS) + if (status != PJ_SUCCESS) { + thread_suspended_tls_id = -1; return status; + } # if PJ_LOG_ENABLE_INDENT status = pj_thread_local_alloc(&thread_indent_tls_id); if (status != PJ_SUCCESS) { pj_thread_local_free(thread_suspended_tls_id); thread_suspended_tls_id = -1; + thread_indent_tls_id = -1; return status; } # endif diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c index 99f9c320b..3c0db2e1c 100644 --- a/pjlib/src/pj/os_core_win32.c +++ b/pjlib/src/pj/os_core_win32.c @@ -918,6 +918,7 @@ PJ_DEF(pj_atomic_value_t) pj_atomic_add_and_get( pj_atomic_t *atomic_var, */ PJ_DEF(pj_status_t) pj_thread_local_alloc(long *index) { + DWORD tls_index; PJ_ASSERT_RETURN(index != NULL, PJ_EINVAL); //Can't check stack because this function is called in the @@ -925,15 +926,17 @@ PJ_DEF(pj_status_t) pj_thread_local_alloc(long *index) //PJ_CHECK_STACK(); #if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8 - *index = TlsAllocRT(); + tls_index = TlsAllocRT(); #else - *index = TlsAlloc(); + tls_index = TlsAlloc(); #endif - if (*index == TLS_OUT_OF_INDEXES) + if (tls_index == TLS_OUT_OF_INDEXES) return PJ_RETURN_OS_ERROR(GetLastError()); - else + else { + *index = (long)tls_index; return PJ_SUCCESS; + } } /* diff --git a/pjlib/src/pj/pool_caching.c b/pjlib/src/pj/pool_caching.c index 0e665a6b3..9d3abdf95 100644 --- a/pjlib/src/pj/pool_caching.c +++ b/pjlib/src/pj/pool_caching.c @@ -17,6 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include +#include #include #include #include @@ -55,6 +56,7 @@ PJ_DEF(void) pj_caching_pool_init( pj_caching_pool *cp, { int i; pj_pool_t *pool; + pj_status_t status; PJ_CHECK_STACK(); @@ -77,7 +79,10 @@ PJ_DEF(void) pj_caching_pool_init( pj_caching_pool *cp, cp->factory.on_block_free = &cpool_on_block_free; pool = pj_pool_create_on_buf("cachingpool", cp->pool_buf, sizeof(cp->pool_buf)); - pj_lock_create_simple_mutex(pool, "cachingpool", &cp->lock); + status = pj_lock_create_simple_mutex(pool, "cachingpool", &cp->lock); + /* This mostly serves to silent coverity warning about unchecked + * return value. There's not much we can do if it fails. */ + PJ_ASSERT_ON_FAIL(status==PJ_SUCCESS, return); } PJ_DEF(void) pj_caching_pool_destroy( pj_caching_pool *cp ) diff --git a/pjlib/src/pj/string.c b/pjlib/src/pj/string.c index d48823e7e..4d001f1a2 100644 --- a/pjlib/src/pj/string.c +++ b/pjlib/src/pj/string.c @@ -275,11 +275,10 @@ PJ_DEF(pj_status_t) pj_strtol2(const pj_str_t *str, long *value) PJ_CHECK_STACK(); - PJ_ASSERT_RETURN(str->slen >= 0, PJ_EINVAL); - if (!str || !value) { return PJ_EINVAL; } + PJ_ASSERT_RETURN(str->slen >= 0, PJ_EINVAL); s = *str; pj_strltrim(&s); @@ -380,12 +379,11 @@ PJ_DEF(pj_status_t) pj_strtoul3(const pj_str_t *str, unsigned long *value, PJ_CHECK_STACK(); - PJ_ASSERT_RETURN(str->slen >= 0, PJ_EINVAL); - if (!str || !value) { return PJ_EINVAL; } - + PJ_ASSERT_RETURN(str->slen >= 0, PJ_EINVAL); + s = *str; pj_strltrim(&s); diff --git a/pjlib/src/pjlib-test/activesock.c b/pjlib/src/pjlib-test/activesock.c index 54733fbb5..29f811766 100644 --- a/pjlib/src/pjlib-test/activesock.c +++ b/pjlib/src/pjlib-test/activesock.c @@ -98,7 +98,6 @@ static pj_status_t udp_echo_srv_create(pj_pool_t *pool, struct udp_echo_srv **p_srv) { struct udp_echo_srv *srv; - pj_sock_t sock_fd = PJ_INVALID_SOCKET; pj_sockaddr addr; pj_activesock_cb activesock_cb; pj_status_t status; @@ -114,7 +113,6 @@ static pj_status_t udp_echo_srv_create(pj_pool_t *pool, status = pj_activesock_create_udp(pool, &addr, NULL, ioqueue, &activesock_cb, srv, &srv->asock, &addr); if (status != PJ_SUCCESS) { - pj_sock_close(sock_fd); udp_echo_err("pj_activesock_create()", status); return status; } diff --git a/pjlib/src/pjlib-test/ioq_stress_test.c b/pjlib/src/pjlib-test/ioq_stress_test.c index 6a0778fd9..0eae04b25 100644 --- a/pjlib/src/pjlib-test/ioq_stress_test.c +++ b/pjlib/src/pjlib-test/ioq_stress_test.c @@ -728,8 +728,10 @@ static int perform_test(test_desc *test) on_return: if (test->state.ioq) pj_ioqueue_destroy(test->state.ioq); - pj_grp_lock_dec_ref(test->state.grp_lock); - test->state.grp_lock = NULL; + if (test->state.grp_lock) { + pj_grp_lock_dec_ref(test->state.grp_lock); + test->state.grp_lock = NULL; + } if (test->state.pool) pj_pool_release(test->state.pool); diff --git a/pjlib/src/pjlib-test/ioq_udp.c b/pjlib/src/pjlib-test/ioq_udp.c index bf1432510..ec5248ad0 100644 --- a/pjlib/src/pjlib-test/ioq_udp.c +++ b/pjlib/src/pjlib-test/ioq_udp.c @@ -1153,9 +1153,9 @@ static int bench_test(const pj_ioqueue_cfg *cfg, int bufsize, on_error: PJ_LOG(1,(THIS_FILE, "...ERROR: %s", pj_strerror(pj_get_netos_error(), errbuf, sizeof(errbuf)))); - if (ssock) + if (ssock > 0) pj_sock_close(ssock); - if (csock) + if (csock > 0) pj_sock_close(csock); for (i=0; isin_addr)); - strcpy(addr_str, pj_inet_ntoa(addr.sin_addr)); + pj_ansi_strncpy(srcaddr_str, pj_inet_ntoa(srcaddr->sin_addr), + sizeof(srcaddr_str)); + pj_ansi_strncpy(addr_str, pj_inet_ntoa(addr.sin_addr), + sizeof(addr_str)); PJ_LOG(3,("test", "...error: src address mismatch (original=%s, " "recvfrom addr=%s)", srcaddr_str, addr_str)); diff --git a/pjlib/src/pjlib-test/timer.c b/pjlib/src/pjlib-test/timer.c index 94725afad..e307ca1fc 100644 --- a/pjlib/src/pjlib-test/timer.c +++ b/pjlib/src/pjlib-test/timer.c @@ -436,6 +436,7 @@ static int poll_worker(void *arg) return 0; } +#if ST_CANCEL_THREAD_COUNT /* Cancel worker thread function. */ static int cancel_worker(void *arg) { @@ -466,6 +467,7 @@ static int cancel_worker(void *arg) return 0; } +#endif static int timer_stress_test(void) { @@ -627,11 +629,11 @@ static int timer_stress_test(void) } /* Start cancel worker threads */ - if (ST_CANCEL_THREAD_COUNT) { - cancel_threads = (pj_thread_t**) - pj_pool_calloc(pool, ST_CANCEL_THREAD_COUNT, - sizeof(pj_thread_t*)); - } +#if ST_CANCEL_THREAD_COUNT + cancel_threads = (pj_thread_t**) + pj_pool_calloc(pool, ST_CANCEL_THREAD_COUNT, + sizeof(pj_thread_t*)); + for (i=0; i