Fixed misc potential bugs as detected by coverity scan
This commit is contained in:
parent
8c2f28ee8a
commit
7615589583
|
@ -151,14 +151,17 @@ pj_status_t pj_log_init(void)
|
||||||
if (thread_suspended_tls_id == -1) {
|
if (thread_suspended_tls_id == -1) {
|
||||||
pj_status_t status;
|
pj_status_t status;
|
||||||
status = pj_thread_local_alloc(&thread_suspended_tls_id);
|
status = pj_thread_local_alloc(&thread_suspended_tls_id);
|
||||||
if (status != PJ_SUCCESS)
|
if (status != PJ_SUCCESS) {
|
||||||
|
thread_suspended_tls_id = -1;
|
||||||
return status;
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
# if PJ_LOG_ENABLE_INDENT
|
# if PJ_LOG_ENABLE_INDENT
|
||||||
status = pj_thread_local_alloc(&thread_indent_tls_id);
|
status = pj_thread_local_alloc(&thread_indent_tls_id);
|
||||||
if (status != PJ_SUCCESS) {
|
if (status != PJ_SUCCESS) {
|
||||||
pj_thread_local_free(thread_suspended_tls_id);
|
pj_thread_local_free(thread_suspended_tls_id);
|
||||||
thread_suspended_tls_id = -1;
|
thread_suspended_tls_id = -1;
|
||||||
|
thread_indent_tls_id = -1;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
|
@ -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)
|
PJ_DEF(pj_status_t) pj_thread_local_alloc(long *index)
|
||||||
{
|
{
|
||||||
|
DWORD tls_index;
|
||||||
PJ_ASSERT_RETURN(index != NULL, PJ_EINVAL);
|
PJ_ASSERT_RETURN(index != NULL, PJ_EINVAL);
|
||||||
|
|
||||||
//Can't check stack because this function is called in the
|
//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();
|
//PJ_CHECK_STACK();
|
||||||
|
|
||||||
#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
|
#if defined(PJ_WIN32_WINPHONE8) && PJ_WIN32_WINPHONE8
|
||||||
*index = TlsAllocRT();
|
tls_index = TlsAllocRT();
|
||||||
#else
|
#else
|
||||||
*index = TlsAlloc();
|
tls_index = TlsAlloc();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (*index == TLS_OUT_OF_INDEXES)
|
if (tls_index == TLS_OUT_OF_INDEXES)
|
||||||
return PJ_RETURN_OS_ERROR(GetLastError());
|
return PJ_RETURN_OS_ERROR(GetLastError());
|
||||||
else
|
else {
|
||||||
|
*index = (long)tls_index;
|
||||||
return PJ_SUCCESS;
|
return PJ_SUCCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
#include <pj/pool.h>
|
#include <pj/pool.h>
|
||||||
|
#include <pj/assert.h>
|
||||||
#include <pj/log.h>
|
#include <pj/log.h>
|
||||||
#include <pj/string.h>
|
#include <pj/string.h>
|
||||||
#include <pj/assert.h>
|
#include <pj/assert.h>
|
||||||
|
@ -55,6 +56,7 @@ PJ_DEF(void) pj_caching_pool_init( pj_caching_pool *cp,
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
pj_pool_t *pool;
|
pj_pool_t *pool;
|
||||||
|
pj_status_t status;
|
||||||
|
|
||||||
PJ_CHECK_STACK();
|
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;
|
cp->factory.on_block_free = &cpool_on_block_free;
|
||||||
|
|
||||||
pool = pj_pool_create_on_buf("cachingpool", cp->pool_buf, sizeof(cp->pool_buf));
|
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 )
|
PJ_DEF(void) pj_caching_pool_destroy( pj_caching_pool *cp )
|
||||||
|
|
|
@ -275,11 +275,10 @@ PJ_DEF(pj_status_t) pj_strtol2(const pj_str_t *str, long *value)
|
||||||
|
|
||||||
PJ_CHECK_STACK();
|
PJ_CHECK_STACK();
|
||||||
|
|
||||||
PJ_ASSERT_RETURN(str->slen >= 0, PJ_EINVAL);
|
|
||||||
|
|
||||||
if (!str || !value) {
|
if (!str || !value) {
|
||||||
return PJ_EINVAL;
|
return PJ_EINVAL;
|
||||||
}
|
}
|
||||||
|
PJ_ASSERT_RETURN(str->slen >= 0, PJ_EINVAL);
|
||||||
|
|
||||||
s = *str;
|
s = *str;
|
||||||
pj_strltrim(&s);
|
pj_strltrim(&s);
|
||||||
|
@ -380,11 +379,10 @@ PJ_DEF(pj_status_t) pj_strtoul3(const pj_str_t *str, unsigned long *value,
|
||||||
|
|
||||||
PJ_CHECK_STACK();
|
PJ_CHECK_STACK();
|
||||||
|
|
||||||
PJ_ASSERT_RETURN(str->slen >= 0, PJ_EINVAL);
|
|
||||||
|
|
||||||
if (!str || !value) {
|
if (!str || !value) {
|
||||||
return PJ_EINVAL;
|
return PJ_EINVAL;
|
||||||
}
|
}
|
||||||
|
PJ_ASSERT_RETURN(str->slen >= 0, PJ_EINVAL);
|
||||||
|
|
||||||
s = *str;
|
s = *str;
|
||||||
pj_strltrim(&s);
|
pj_strltrim(&s);
|
||||||
|
|
|
@ -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 **p_srv)
|
||||||
{
|
{
|
||||||
struct udp_echo_srv *srv;
|
struct udp_echo_srv *srv;
|
||||||
pj_sock_t sock_fd = PJ_INVALID_SOCKET;
|
|
||||||
pj_sockaddr addr;
|
pj_sockaddr addr;
|
||||||
pj_activesock_cb activesock_cb;
|
pj_activesock_cb activesock_cb;
|
||||||
pj_status_t status;
|
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,
|
status = pj_activesock_create_udp(pool, &addr, NULL, ioqueue, &activesock_cb,
|
||||||
srv, &srv->asock, &addr);
|
srv, &srv->asock, &addr);
|
||||||
if (status != PJ_SUCCESS) {
|
if (status != PJ_SUCCESS) {
|
||||||
pj_sock_close(sock_fd);
|
|
||||||
udp_echo_err("pj_activesock_create()", status);
|
udp_echo_err("pj_activesock_create()", status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -728,8 +728,10 @@ static int perform_test(test_desc *test)
|
||||||
on_return:
|
on_return:
|
||||||
if (test->state.ioq)
|
if (test->state.ioq)
|
||||||
pj_ioqueue_destroy(test->state.ioq);
|
pj_ioqueue_destroy(test->state.ioq);
|
||||||
pj_grp_lock_dec_ref(test->state.grp_lock);
|
if (test->state.grp_lock) {
|
||||||
test->state.grp_lock = NULL;
|
pj_grp_lock_dec_ref(test->state.grp_lock);
|
||||||
|
test->state.grp_lock = NULL;
|
||||||
|
}
|
||||||
if (test->state.pool)
|
if (test->state.pool)
|
||||||
pj_pool_release(test->state.pool);
|
pj_pool_release(test->state.pool);
|
||||||
|
|
||||||
|
|
|
@ -1153,9 +1153,9 @@ static int bench_test(const pj_ioqueue_cfg *cfg, int bufsize,
|
||||||
on_error:
|
on_error:
|
||||||
PJ_LOG(1,(THIS_FILE, "...ERROR: %s",
|
PJ_LOG(1,(THIS_FILE, "...ERROR: %s",
|
||||||
pj_strerror(pj_get_netos_error(), errbuf, sizeof(errbuf))));
|
pj_strerror(pj_get_netos_error(), errbuf, sizeof(errbuf))));
|
||||||
if (ssock)
|
if (ssock > 0)
|
||||||
pj_sock_close(ssock);
|
pj_sock_close(ssock);
|
||||||
if (csock)
|
if (csock > 0)
|
||||||
pj_sock_close(csock);
|
pj_sock_close(csock);
|
||||||
for (i=0; i<inactive_sock_count && inactive_sock &&
|
for (i=0; i<inactive_sock_count && inactive_sock &&
|
||||||
inactive_sock[i]!=PJ_INVALID_SOCKET; ++i)
|
inactive_sock[i]!=PJ_INVALID_SOCKET; ++i)
|
||||||
|
|
|
@ -122,6 +122,10 @@ static int sleep_duration_test(void)
|
||||||
|
|
||||||
/* Mark end of test. */
|
/* Mark end of test. */
|
||||||
rc = pj_gettimeofday(&stop);
|
rc = pj_gettimeofday(&stop);
|
||||||
|
if (rc != PJ_SUCCESS) {
|
||||||
|
app_perror("...error: pj_gettimeofday()", rc);
|
||||||
|
return -22;
|
||||||
|
}
|
||||||
|
|
||||||
/* Calculate duration (store in stop). */
|
/* Calculate duration (store in stop). */
|
||||||
PJ_TIME_VAL_SUB(stop, start);
|
PJ_TIME_VAL_SUB(stop, start);
|
||||||
|
|
|
@ -512,8 +512,10 @@ static int send_recv_test(int sock_type,
|
||||||
return -151;
|
return -151;
|
||||||
if (pj_sockaddr_cmp(&addr, srcaddr) != 0) {
|
if (pj_sockaddr_cmp(&addr, srcaddr) != 0) {
|
||||||
char srcaddr_str[32], addr_str[32];
|
char srcaddr_str[32], addr_str[32];
|
||||||
strcpy(srcaddr_str, pj_inet_ntoa(srcaddr->sin_addr));
|
pj_ansi_strncpy(srcaddr_str, pj_inet_ntoa(srcaddr->sin_addr),
|
||||||
strcpy(addr_str, pj_inet_ntoa(addr.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, "
|
PJ_LOG(3,("test", "...error: src address mismatch (original=%s, "
|
||||||
"recvfrom addr=%s)",
|
"recvfrom addr=%s)",
|
||||||
srcaddr_str, addr_str));
|
srcaddr_str, addr_str));
|
||||||
|
|
|
@ -436,6 +436,7 @@ static int poll_worker(void *arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ST_CANCEL_THREAD_COUNT
|
||||||
/* Cancel worker thread function. */
|
/* Cancel worker thread function. */
|
||||||
static int cancel_worker(void *arg)
|
static int cancel_worker(void *arg)
|
||||||
{
|
{
|
||||||
|
@ -466,6 +467,7 @@ static int cancel_worker(void *arg)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int timer_stress_test(void)
|
static int timer_stress_test(void)
|
||||||
{
|
{
|
||||||
|
@ -627,11 +629,11 @@ static int timer_stress_test(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start cancel worker threads */
|
/* Start cancel worker threads */
|
||||||
if (ST_CANCEL_THREAD_COUNT) {
|
#if ST_CANCEL_THREAD_COUNT
|
||||||
cancel_threads = (pj_thread_t**)
|
cancel_threads = (pj_thread_t**)
|
||||||
pj_pool_calloc(pool, ST_CANCEL_THREAD_COUNT,
|
pj_pool_calloc(pool, ST_CANCEL_THREAD_COUNT,
|
||||||
sizeof(pj_thread_t*));
|
sizeof(pj_thread_t*));
|
||||||
}
|
|
||||||
for (i=0; i<ST_CANCEL_THREAD_COUNT; ++i) {
|
for (i=0; i<ST_CANCEL_THREAD_COUNT; ++i) {
|
||||||
status = pj_thread_create( pool, "cancel", &cancel_worker, &tparam,
|
status = pj_thread_create( pool, "cancel", &cancel_worker, &tparam,
|
||||||
0, 0, &cancel_threads[i]);
|
0, 0, &cancel_threads[i]);
|
||||||
|
@ -641,6 +643,7 @@ static int timer_stress_test(void)
|
||||||
goto on_return;
|
goto on_return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if SIMULATE_CRASH
|
#if SIMULATE_CRASH
|
||||||
tmp_pool = pj_pool_create( mem, NULL, 4096, 128, NULL);
|
tmp_pool = pj_pool_create( mem, NULL, 4096, 128, NULL);
|
||||||
|
@ -668,7 +671,7 @@ on_return:
|
||||||
tparam.stopping = PJ_TRUE;
|
tparam.stopping = PJ_TRUE;
|
||||||
|
|
||||||
for (i=0; i<ST_STRESS_THREAD_COUNT; ++i) {
|
for (i=0; i<ST_STRESS_THREAD_COUNT; ++i) {
|
||||||
if (!stress_threads[i])
|
if (!stress_threads || !stress_threads[i])
|
||||||
continue;
|
continue;
|
||||||
pj_thread_join(stress_threads[i]);
|
pj_thread_join(stress_threads[i]);
|
||||||
pj_thread_destroy(stress_threads[i]);
|
pj_thread_destroy(stress_threads[i]);
|
||||||
|
|
Loading…
Reference in New Issue