{"action":"closed","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/18117","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/18117/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/18117/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/18117/events","html_url":"https://github.com/rust-lang/rust/issues/18117","id":46090393,"number":18117,"title":"Incorrect const-ness on CString::new argument","user":{"login":"canndrew","id":5555066,"avatar_url":"https://avatars.githubusercontent.com/u/5555066?v=3","gravatar_id":"","url":"https://api.github.com/users/canndrew","html_url":"https://github.com/canndrew","followers_url":"https://api.github.com/users/canndrew/followers","following_url":"https://api.github.com/users/canndrew/following{/other_user}","gists_url":"https://api.github.com/users/canndrew/gists{/gist_id}","starred_url":"https://api.github.com/users/canndrew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/canndrew/subscriptions","organizations_url":"https://api.github.com/users/canndrew/orgs","repos_url":"https://api.github.com/users/canndrew/repos","events_url":"https://api.github.com/users/canndrew/events{/privacy}","received_events_url":"https://api.github.com/users/canndrew/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-10-17T11:41:01Z","updated_at":"2015-01-19T00:21:11Z","closed_at":"2015-01-19T00:21:11Z","body":"The signature of `CString::new` is `CString::new(buf: *const i8, owns_buffer: bool)`. The problem with this is that if the new `CString` does own the buffer it's going to free it. In which case `buf` should be a `*mut i8` not a `*const i8`. However making `buf: *mut i8` doesn't account for the case where the `CString` doesn't own the buffer and the buffer is immutable.\r\n\r\nTo fix this `CString::new` should be split into two functions:\r\n\r\n    unsafe fn CString::new(buf: *const i8) -> CString;\r\n    unsafe fn CString::new_owned(buf: *mut i8) -> CString;\r\n\r\n"}}