From bed64351c23e199058152fe6333a003af6787e92 Mon Sep 17 00:00:00 2001 From: "Samuel K. Gutierrez" Date: Wed, 18 Sep 2024 05:27:20 -0600 Subject: [PATCH] Plug a memory leak in pthread example. Signed-off-by: Samuel K. Gutierrez --- src/qvi-pthread.cc | 2 +- tests/test-pthread-split.c | 33 ++++++++++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/qvi-pthread.cc b/src/qvi-pthread.cc index f71da8c..97f5995 100644 --- a/src/qvi-pthread.cc +++ b/src/qvi-pthread.cc @@ -142,7 +142,7 @@ qvi_pthread_group::task(void) int qvi_pthread_group::barrier(void) { - const int rc = pthread_barrier_wait(&(m_barrier)); + const int rc = pthread_barrier_wait(&m_barrier); if (qvi_unlikely((rc != 0) && (rc != PTHREAD_BARRIER_SERIAL_THREAD))) { return QV_ERR_INTERNAL; } diff --git a/tests/test-pthread-split.c b/tests/test-pthread-split.c index a512fb5..74a6585 100644 --- a/tests/test-pthread-split.c +++ b/tests/test-pthread-split.c @@ -33,7 +33,6 @@ thread_work( fprintf(stdout,"[%d] Thread running on %s\n", tid, binds); free(binds); - qv_scope_t *out_scope = NULL; int rank = -1; rc = qv_scope_group_rank(thargs->scope, &rank); if (rc != QV_SUCCESS) { @@ -41,14 +40,21 @@ thread_work( qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc)); } - fprintf(stdout,"=== [%d] Thread %i splitting in two pieces\n", tid, rank); + fprintf(stdout,"[%d] Thread %d splitting in two pieces\n", tid, rank); + qv_scope_t *out_scope = NULL; rc = qv_scope_split(thargs->scope, 2, rank, &out_scope); if (rc != QV_SUCCESS) { ers = "qv_scope_split failed"; qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc)); } + rc = qv_scope_free(out_scope); + if (rc != QV_SUCCESS) { + ers = "qv_scope_free failed"; + qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc)); + } + return NULL; } @@ -95,21 +101,15 @@ main(void) ers = "qv_scope_nobjs() failed"; qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc)); } - - //test qv_pthread_scope_split - int npieces = 2; //ncores / 2; + // + // Test qv_pthread_scope_split + // + int npieces = 2; int nthreads = ncores; - - fprintf(stdout,"[%d] ====== Testing thread_scope_split (number of threads : %i)\n", tid, nthreads); + printf("[%d] Testing thread_scope_split (nthreads=%i)\n", tid, nthreads); int colors[nthreads]; - - /* - for (int i = 0 ; i < nthreads ; i++) { - colors[i] = i % npieces; - } - */ rc = qv_pthread_colors_fill(colors, nthreads, QV_POLICY_PACKED, 1, npieces); if (rc != QV_SUCCESS) { ers = "qv_pthread_colors_fill() failed"; @@ -152,14 +152,13 @@ main(void) } //fprintf(stdout,"Thread finished with '%s'\n", (char *)ret); } - - /* Clean up */ + // Clean up. rc = qv_pthread_scopes_free(nthreads, th_scopes); if (rc != QV_SUCCESS) { ers = "qv_pthread_scope_free() failed"; qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc)); } - +#if 0 //Test qv_pthread_scope_split_at nthreads = 2 * ncores; @@ -216,7 +215,7 @@ main(void) ers = "qv_pthread_scope_free() failed"; qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc)); } - +#endif rc = qv_scope_free(mpi_scope); if (rc != QV_SUCCESS) { ers = "qv_scope_free() failed";