From 3c2573917024c89bb2b53079ca196fe13ea74b1f Mon Sep 17 00:00:00 2001 From: David Greenberg Date: Wed, 15 Jul 2015 09:12:36 -0400 Subject: [PATCH] Free err strings correctly --- src/rocksdb.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rocksdb.rs b/src/rocksdb.rs index 59c2413..d20a24a 100644 --- a/src/rocksdb.rs +++ b/src/rocksdb.rs @@ -163,8 +163,11 @@ pub trait Writable { fn error_message(ptr: *const i8) -> String { let c_str = unsafe { CStr::from_ptr(ptr) }; -//TODO I think we're leaking the c string here; should be a call to free once realloced into rust String - from_utf8(c_str.to_bytes()).unwrap().to_owned() + let s = from_utf8(c_str.to_bytes()).unwrap().to_owned(); + unsafe{ + libc::free(ptr as *mut libc::c_void); + } + s } impl RocksDB {