Fix imp_getBlock/imp_removeBlock for struct-return block IMPs#390
Open
DTW-Thalion wants to merge 1 commit into
Open
Fix imp_getBlock/imp_removeBlock for struct-return block IMPs#390DTW-Thalion wants to merge 1 commit into
DTW-Thalion wants to merge 1 commit into
Conversation
When the IMP is not found in the regular trampoline set, both functions fall back to searching sret_trampolines but discarded the result of the second indexForIMP() call, leaving idx at -1. imp_getBlock therefore always returned NULL for a struct-return block IMP, and imp_removeBlock returned NO without releasing the block (a leak). Assign the second indexForIMP() result to idx. Extend Test/BlockImpTest.m to check imp_getBlock and imp_removeBlock on the struct-return IMP it already creates.
davidchisnall
approved these changes
Jun 29, 2026
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.
Summary
imp_getBlockandimp_removeBlockfirst look the IMP up in the regulartrampoline set; if that misses, they fall back to
sret_trampolines. But thefallback discarded the result of the second
indexForIMP()call, leavingidxat-1:As a result
imp_getBlockalways returnedNULLfor a struct-return (sret)block IMP, and
imp_removeBlockreturnedNOwithout releasing the block —leaking the block and its trampoline slot.
Fix
Assign the fallback
indexForIMP()result toidxin both functions.Reproduction / test
Test/BlockImpTest.malready creates an sret block IMP (thestruct bigblock) but only checked
imp_getBlock/imp_removeBlockon the non-sret IMP.Before the fix, asserting
imp_getBlock(imp) == blkon the sret IMP fails(returns
NULL); after, it passes. The test now exercises both functions onthe struct-return IMP (all four BlockImpTest variants pass).