We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d6caa8e commit 00fe4f8Copy full SHA for 00fe4f8
1 file changed
src/qiskit.rs
@@ -466,9 +466,12 @@ impl Observable {
466
unsafe { qiskit_sys::qk_obs_equal(self.observable, obs.observable) }
467
}
468
/// Return a string representation of the observable
469
- pub fn str(&self) -> &str {
+ pub fn str(&self) -> String {
470
let obs_str = unsafe { qiskit_sys::qk_obs_str(self.observable) };
471
- unsafe { CStr::from_ptr(obs_str) }.to_str().unwrap()
+ // Clone C string into String, which implements Drop
472
+ let retval = String::from(unsafe { CStr::from_ptr(obs_str) }.to_str().unwrap());
473
+ unsafe { qiskit_sys::qk_str_free(obs_str) };
474
+ retval
475
476
477
0 commit comments