Skip to content

[Backport v2.7] tests: posix: pthread: init pthread_attr_t on each iteration #57413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions tests/posix/common/src/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,17 +563,15 @@ void test_posix_pthread_create_negative(void)

void test_pthread_descriptor_leak(void)
{
void *unused;
pthread_t pthread1;
pthread_attr_t attr;

zassert_ok(pthread_attr_init(&attr), NULL);
zassert_ok(pthread_attr_setstack(&attr, &stack_e[0][0], STACKS), NULL);

/* If we are leaking descriptors, then this loop will never complete */
for (size_t i = 0; i < CONFIG_MAX_PTHREAD_COUNT * 2; ++i) {
zassert_ok(pthread_create(&pthread1, &attr, create_thread1, NULL),
zassert_equal(0, pthread_attr_init(&attr), NULL);
zassert_equal(0, pthread_attr_setstack(&attr, &stack_e[0][0], STACKS), NULL);
zassert_equal(0, pthread_create(&pthread1, &attr, create_thread1, NULL),
"unable to create thread %zu", i);
zassert_ok(pthread_join(pthread1, &unused), "unable to join thread %zu", i);
zassert_equal(0, pthread_join(pthread1, NULL), "unable to join thread %zu", i);
}
}