Skip to content

[cxx-interop] Fix a potential dangling pointer in String(cxxString:) #59297

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

Merged
merged 1 commit into from
Jun 7, 2022

Conversation

egorzhdan
Copy link
Contributor

cxxString might get deallocated immediately after c_str() call, which would mean that the pointer passed to String(cString:) points to invalid memory.

We haven't actually seen this, but let's preemptively add an explicit withExtendedLifetime call to avoid running into this in the future.

Similar to #59152.

`cxxString` might get deallocated immediately after `c_str()` call, which would mean that the pointer passed to `String(cString:)` points to invalid memory.

We haven't actually seen this, but let's preemptively add an explicit `withExtendedLifetime` call to avoid running into this in the future.
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jun 7, 2022
@egorzhdan egorzhdan requested a review from zoecarver June 7, 2022 15:59
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan merged commit 59bb4cb into main Jun 7, 2022
@egorzhdan egorzhdan deleted the egorzhdan/cxx-overlay-dangling-ptr branch June 7, 2022 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant