Skip to content
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

An improper locking due to the unreleased lock before program exit #94

Closed
ycaibb opened this issue Sep 7, 2021 · 2 comments
Closed

Comments

@ycaibb
Copy link

ycaibb commented Sep 7, 2021

Hi developers, in the below codes, the lock threads_lock could be not released before program's exit fail(). I think it is better to write release_(&(threads_lock), file, line); before the abort(); for better resource management and code symmetry. Thanks!

pigz/yarn.c

Lines 307 to 329 in b6da942

possess_(&(threads_lock), file, line);
// create the thread and call ignition() from that thread
thread *th = my_malloc(sizeof(struct thread_s), file, line);
pthread_attr_t attr;
int ret = pthread_attr_init(&attr);
if (ret)
fail(ret, file, line, "attr_init");
ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
if (ret)
fail(ret, file, line, "attr_setdetachstate");
ret = pthread_create(&(th->id), &attr, ignition, capsule);
if (ret)
fail(ret, file, line, "create");
ret = pthread_attr_destroy(&attr);
if (ret)
fail(ret, file, line, "attr_destroy");
// put the thread in the threads list for join_all()
th->done = 0;
th->next = threads;
threads = th;
release_(&(threads_lock), file, line);

Best,

@ycaibb
Copy link
Author

ycaibb commented Sep 13, 2021

Hi, developers @madler

Any comments would be highly appreciated. Thank you.

Best Regards,

@madler
Copy link
Owner

madler commented Jan 14, 2022

There's no point in attempting to clean up, as the program immediately exits.

@madler madler closed this as completed Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants