Are you sure you're not using source.as_ptr() value outside scope of the variable anywhere? The temporary validity of the pointer is the common source of crashes here.
SOLVED
Inside bar() I call from_raw() breaking the safety rule. I passed a pointer value that was generated by opengl function.
I switched to use String::from_raw_parts instead of CString and the problem has gone.
let mut log: [i8; 512] = [0; 512];
let log_ptr: *mut i8 = &mut log[0];
let length: *mut i32 = &mut 0;
gl.GetShaderInfoLog(shader, 512, length, log_ptr);
// let s = CString::from_raw(log_ptr);
let s = String::from_raw_parts(log_ptr as *mut u8, *length as usize, 512);
println!("{:?}", s);
Yeah, that would do it . You've probably already seen it, but CStr can be used to view a C string without taking ownership of it (it's basically the &str analog to Rust's String, but for CString).
This may crash and cause corruption as well, because Rust will try to free String's pointer using its jemalloc, and you're using stack-allocated object here.
String::from_raw_parts is a risky hack that you shouldn't normally need, and it's probably unsafe to use with anything other than another String or Vec's raw parts, carefully taken.