hts_newthread() leaves the pthread attributes object undestroyed when thread creation fails#807
Open
xroche wants to merge 9 commits into
Open
hts_newthread() leaves the pthread attributes object undestroyed when thread creation fails#807xroche wants to merge 9 commits into
xroche wants to merge 9 commits into
Conversation
… thread creation fails hts_newthread() folds pthread_attr_init(), pthread_attr_setstacksize() and pthread_create() into one short-circuit condition, and destroys the attributes object only on the branch where all three succeeded. If setstacksize or create fails (EAGAIN under thread or memory exhaustion being the realistic case), attr stays initialised for good. glibc allocates nothing for a default-initialised attr, so nothing actually leaks on Linux. This is a portability and hygiene fix rather than a live bug. The init has to come out of the chain instead of just gaining a destroy call: the shared condition cannot tell which of the three failed, and destroying an object pthread_attr_init() never initialised is undefined. The imbalance is invisible to a leak checker, so the test counts it directly. A small LD_PRELOAD shim refuses pthread_create() and records which attributes objects nobody destroyed afterwards: 1 undestroyed on master, 0 with the fix. Closes #772 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
Condense the two-line note above pthread_attr_init(), fix the "so that is can be independent" typo on the line the diff moves, and count a refused spawn as tested only when it carried an attributes object, so a NULL-attr create from elsewhere cannot satisfy the guard on its own. Note why the shim's fixed slot count and unlocked counters are enough. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
Resolve the tests/Makefile.am TESTS-tail conflict: keep both 111 and 113 entries in numeric order. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
Resolve the tests/Makefile.am TESTS-tail conflict: keep 110, 111 and 113 in numeric order. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
Fix the TESTS-tail union merge's missing continuation backslash. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
Register 113_engine-threadattr-leak.test in tests-list.mk after the #845 TESTS-list restructure moved it out of tests/Makefile.am, and keep this branch's libthreadattrfail build rules (EXTRA_DIST, TESTS_ENVIRONMENT, check_LTLIBRARIES, *_la_* rules) that a wholesale take-master resolution had dropped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
xroche
force-pushed
the
fix/thread-attr-leak-772
branch
from
July 27, 2026 17:41
efd2d1c to
469952a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hts_newthread()foldspthread_attr_init(),pthread_attr_setstacksize()andpthread_create()into one short-circuit condition, and destroys the attributes object only on the branch where all three succeeded. If setstacksize or create fails (EAGAIN under thread or memory exhaustion being the realistic case),attrstays initialised for good. glibc allocates nothing for a default-initialised attr, so nothing actually leaks on Linux. This is a portability and hygiene fix rather than a live bug.The init has to come out of the chain instead of just gaining a destroy call: the shared condition cannot tell which of the three failed, and destroying an object
pthread_attr_init()never initialised is undefined.The imbalance is invisible to a leak checker, so the test counts it directly. A small LD_PRELOAD shim refuses
pthread_create()and records which attributes objects nobody destroyed afterwards: 1 undestroyed on master, 0 with the fix.Closes #772