-
Notifications
You must be signed in to change notification settings - Fork 749
Use a local strong NSError for methods with nested autorelease pool #10465
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
Conversation
…asepool Otherwise, the output NSError arg get assigned an autoreleasing NSError object that gets deallocated when the nested autorelease pool is drained and no error is reported
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/10465
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit a825597 with merge base 9e59c19 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@cymbalrush ptal |
|
Can you add a regression test that exercises this path? Namely, a test that will crash before this PR but will succeed with this PR. |
Thanks for fixing it! I don't think there are other places where we explicitly create an |
|
@shoumikhin has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@shoumikhin @larryliu0820 are there any objections on not creating a test? |
|
@mergennachin sorry, missed that request, adding a test in #10537 |
Otherwise, the out
NSErrorarg get assigned an autoreleasingNSErrorobject that gets deallocated when the nested autorelease pool is drained and no error is reported:We introduce a local error var to hold onto the autoreleased
NSErrorcreated by some other API likefooand use it to initialize the outNSErrorarg:Another important observation is that generally it's required to check if the out
NSErrorhas been set despite the returned status.And a more trickier crash happens even before the control reaches error handling. The compiler assumes the error local var in the
runmethod is__strong, so it generatesobjc_storeStrongcall. Whereas in fact it points to an__autoreleasingobject (that gets deallocated when the pool drains as we clarified), and thus such a call on it will lead to a crash regardless, we won't even reach the code that tries to accesscodeon it. Unless we indeed introduce a local strong var insidebarto be assigned to the outNSErrorarg and so make the generatedobjc_storeStrongcall a legit one. Although, that issue can technically be resolved differently - by markingerrorvar inrunas__autoreleasingto skip theobjc_storeStrongcall. But that still doesn't help reporting the actual error, since it's gonna be nil after the nested autorelease pool drainage insidebar. And apparently having the nested autorelease pool is important enough, so we can't avoid it and have to use such workarounds.