Skip to content

Commit 3ccfee2

Browse files
Plug a memory leak in pthread example. (#279)
Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent 55b884e commit 3ccfee2

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/qvi-pthread.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ qvi_pthread_group::task(void)
142142
int
143143
qvi_pthread_group::barrier(void)
144144
{
145-
const int rc = pthread_barrier_wait(&(m_barrier));
145+
const int rc = pthread_barrier_wait(&m_barrier);
146146
if (qvi_unlikely((rc != 0) && (rc != PTHREAD_BARRIER_SERIAL_THREAD))) {
147147
return QV_ERR_INTERNAL;
148148
}

tests/test-pthread-split.c

+16-17
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,28 @@ thread_work(
3333
fprintf(stdout,"[%d] Thread running on %s\n", tid, binds);
3434
free(binds);
3535

36-
qv_scope_t *out_scope = NULL;
3736
int rank = -1;
3837
rc = qv_scope_group_rank(thargs->scope, &rank);
3938
if (rc != QV_SUCCESS) {
4039
ers = "qv_scope_group_rank failed";
4140
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
4241
}
4342

44-
fprintf(stdout,"=== [%d] Thread %i splitting in two pieces\n", tid, rank);
43+
fprintf(stdout,"[%d] Thread %d splitting in two pieces\n", tid, rank);
4544

45+
qv_scope_t *out_scope = NULL;
4646
rc = qv_scope_split(thargs->scope, 2, rank, &out_scope);
4747
if (rc != QV_SUCCESS) {
4848
ers = "qv_scope_split failed";
4949
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
5050
}
5151

52+
rc = qv_scope_free(out_scope);
53+
if (rc != QV_SUCCESS) {
54+
ers = "qv_scope_free failed";
55+
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
56+
}
57+
5258
return NULL;
5359
}
5460

@@ -95,21 +101,15 @@ main(void)
95101
ers = "qv_scope_nobjs() failed";
96102
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
97103
}
98-
99-
//test qv_pthread_scope_split
100-
int npieces = 2; //ncores / 2;
104+
//
105+
// Test qv_pthread_scope_split
106+
//
107+
int npieces = 2;
101108
int nthreads = ncores;
102109

103-
104-
fprintf(stdout,"[%d] ====== Testing thread_scope_split (number of threads : %i)\n", tid, nthreads);
110+
printf("[%d] Testing thread_scope_split (nthreads=%i)\n", tid, nthreads);
105111

106112
int colors[nthreads];
107-
108-
/*
109-
for (int i = 0 ; i < nthreads ; i++) {
110-
colors[i] = i % npieces;
111-
}
112-
*/
113113
rc = qv_pthread_colors_fill(colors, nthreads, QV_POLICY_PACKED, 1, npieces);
114114
if (rc != QV_SUCCESS) {
115115
ers = "qv_pthread_colors_fill() failed";
@@ -152,14 +152,13 @@ main(void)
152152
}
153153
//fprintf(stdout,"Thread finished with '%s'\n", (char *)ret);
154154
}
155-
156-
/* Clean up */
155+
// Clean up.
157156
rc = qv_pthread_scopes_free(nthreads, th_scopes);
158157
if (rc != QV_SUCCESS) {
159158
ers = "qv_pthread_scope_free() failed";
160159
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
161160
}
162-
161+
#if 0
163162
//Test qv_pthread_scope_split_at
164163
nthreads = 2 * ncores;
165164

@@ -216,7 +215,7 @@ main(void)
216215
ers = "qv_pthread_scope_free() failed";
217216
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
218217
}
219-
218+
#endif
220219
rc = qv_scope_free(mpi_scope);
221220
if (rc != QV_SUCCESS) {
222221
ers = "qv_scope_free() failed";

0 commit comments

Comments
 (0)