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

dangling reference in convert(Ptr{Uint8},String) #1601

Closed
JeffBezanson opened this issue Nov 24, 2012 · 2 comments
Closed

dangling reference in convert(Ptr{Uint8},String) #1601

JeffBezanson opened this issue Nov 24, 2012 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@JeffBezanson
Copy link
Member

This conversion (currently at string.jl:47)

convert(::Type{Ptr{Uint8}}, s::String) = convert(Ptr{Uint8}, bytestring(s))

returns a pointer to an unreferenced object. This is a memory bug.

When bytestring(s) occurs as an argument in ccall, this is not a problem since ccall is designed to keep a reference to the original un-converted arguments.

@StefanKarpinski
Copy link
Member

Should we maybe only define this operation for cconvert and not for convert?

@JeffBezanson
Copy link
Member Author

Yes, cconvert(::Type{Ptr{Uint8}}, s::String) = bytestring(s) would work the same as in the Ptr{Ptr{T}} case, since ccall internally knows how to convert ByteStrings.

JeffBezanson added a commit that referenced this issue Nov 29, 2012
…used by my fix for #1601

non-bytestrings will have to be manually converted to pass to ccall for now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants