{"action":"created","issue":{"url":"https://api.github.com/repos/ffi/ffi/issues/467","labels_url":"https://api.github.com/repos/ffi/ffi/issues/467/labels{/name}","comments_url":"https://api.github.com/repos/ffi/ffi/issues/467/comments","events_url":"https://api.github.com/repos/ffi/ffi/issues/467/events","html_url":"https://github.com/ffi/ffi/issues/467","id":118517559,"number":467,"title":"return type char * as :string ?","user":{"login":"paddor","id":8876,"avatar_url":"https://avatars.githubusercontent.com/u/8876?v=3","gravatar_id":"","url":"https://api.github.com/users/paddor","html_url":"https://github.com/paddor","followers_url":"https://api.github.com/users/paddor/followers","following_url":"https://api.github.com/users/paddor/following{/other_user}","gists_url":"https://api.github.com/users/paddor/gists{/gist_id}","starred_url":"https://api.github.com/users/paddor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paddor/subscriptions","organizations_url":"https://api.github.com/users/paddor/orgs","repos_url":"https://api.github.com/users/paddor/repos","events_url":"https://api.github.com/users/paddor/events{/privacy}","received_events_url":"https://api.github.com/users/paddor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-24T02:11:22Z","updated_at":"2015-11-24T20:21:45Z","closed_at":null,"body":"Sorry, but the docs really aren't clear on this.\r\n\r\nGiven the following C function prototype:\r\n\r\n```c\r\nchar * somelib_encode (somelib_t *self, const byte *data, size_t data_size);\r\n```\r\n\r\nThe return value is a pointer to a freshly allocated memory area. The caller is responsible for `free()`ing it later.\r\n\r\nIs it safe to attach this function like this?\r\n\r\n```ruby\r\nattach_function :somelib_encode, [:pointer, :pointer, :size_t], :string\r\n```\r\n\r\nI know FFI will properly read the C string (the function guarantees that there's only one trailing NULL byte) and return it as a Ruby String object. But what happens to the memory area?\r\n\r\nDoes FFI have the possibility to examine the exact C function prototype to see if the return value is `const`, and, if not, should be `free()`d later?\r\n\r\nPlease document this clearly."},"comment":{"url":"https://api.github.com/repos/ffi/ffi/issues/comments/159394576","html_url":"https://github.com/ffi/ffi/issues/467#issuecomment-159394576","issue_url":"https://api.github.com/repos/ffi/ffi/issues/467","id":159394576,"user":{"login":"paddor","id":8876,"avatar_url":"https://avatars.githubusercontent.com/u/8876?v=3","gravatar_id":"","url":"https://api.github.com/users/paddor","html_url":"https://github.com/paddor","followers_url":"https://api.github.com/users/paddor/followers","following_url":"https://api.github.com/users/paddor/following{/other_user}","gists_url":"https://api.github.com/users/paddor/gists{/gist_id}","starred_url":"https://api.github.com/users/paddor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paddor/subscriptions","organizations_url":"https://api.github.com/users/paddor/orgs","repos_url":"https://api.github.com/users/paddor/repos","events_url":"https://api.github.com/users/paddor/events{/privacy}","received_events_url":"https://api.github.com/users/paddor/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T20:21:44Z","updated_at":"2015-11-24T20:21:44Z","body":"Thanks for answering the question.\r\n\r\nAlso, thanks for the example. It makes sense, but looks pretty messy. What about AutoPointer? I'm not sure, but it kinda sounds like the thing to use when I want automatic release of memory. "}}