summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Fiekas <niklas.fiekas@backscattering.de>2023-06-21 20:50:25 +0200
committerGitHub <noreply@github.com>2023-06-21 20:50:25 +0200
commite0dab6a098716bf7d237b038049269d7d75145ba (patch)
tree077f959eeca771bb3441e58097f5cb15fabd5039
parentbcf56678050c943922cf10b74ba6480f45a8f26d (diff)
Prefer rocksdb_free to free for RocksDB memory (#794)
-rw-r--r--src/db.rs2
-rw-r--r--src/db_options.rs2
-rw-r--r--src/ffi_util.rs13
-rw-r--r--src/perf.rs2
4 files changed, 10 insertions, 9 deletions
diff --git a/src/db.rs b/src/db.rs
index 1cd44ac..ac3ce10 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -1790,7 +1790,7 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
))),
};
unsafe {
- libc::free(value as *mut c_void);
+ ffi::rocksdb_free(value as *mut c_void);
}
result
}
diff --git a/src/db_options.rs b/src/db_options.rs
index cb8e978..f0b381e 100644
--- a/src/db_options.rs
+++ b/src/db_options.rs
@@ -2529,7 +2529,7 @@ impl Options {
// Must have valid UTF-8 format.
let s = CStr::from_ptr(value).to_str().unwrap().to_owned();
- libc::free(value as *mut c_void);
+ ffi::rocksdb_free(value as *mut c_void);
Some(s)
}
}
diff --git a/src/ffi_util.rs b/src/ffi_util.rs
index 19a9b11..555e3d4 100644
--- a/src/ffi_util.rs
+++ b/src/ffi_util.rs
@@ -13,7 +13,7 @@
// limitations under the License.
//
-use crate::Error;
+use crate::{ffi, Error};
use libc::{self, c_char, c_void, size_t};
use std::ffi::{CStr, CString};
use std::path::Path;
@@ -38,7 +38,7 @@ pub(crate) unsafe fn raw_data(ptr: *const c_char, size: usize) -> Option<Vec<u8>
pub fn error_message(ptr: *const c_char) -> String {
unsafe {
let s = from_cstr(ptr);
- libc::free(ptr as *mut c_void);
+ ffi::rocksdb_free(ptr as *mut c_void);
s
}
}
@@ -207,9 +207,10 @@ impl CSlice {
///
/// # Safety
/// The caller must ensure that the pointer and length are valid.
- /// Moreover, `CSlice` takes the ownership of the memory and will free it using `libc::free`.
- /// The caller must ensure that the memory is allocated by `libc::malloc`
- /// and will not be freed by any other means.
+ /// Moreover, `CSlice` takes the ownership of the memory and will free it
+ /// using `rocksdb_free`. The caller must ensure that the memory is
+ /// allocated by `malloc` in RocksDB and will not be freed by any other
+ /// means.
pub(crate) unsafe fn from_raw_parts(data: *const c_char, len: size_t) -> Self {
Self { data, len }
}
@@ -224,7 +225,7 @@ impl AsRef<[u8]> for CSlice {
impl Drop for CSlice {
fn drop(&mut self) {
unsafe {
- libc::free(self.data as *mut c_void);
+ ffi::rocksdb_free(self.data as *mut c_void);
}
}
}
diff --git a/src/perf.rs b/src/perf.rs
index 6fa7ac0..12644b3 100644
--- a/src/perf.rs
+++ b/src/perf.rs
@@ -155,7 +155,7 @@ impl PerfContext {
let ptr =
ffi::rocksdb_perfcontext_report(self.inner, c_uchar::from(exclude_zero_counters));
let report = from_cstr(ptr);
- libc::free(ptr as *mut c_void);
+ ffi::rocksdb_free(ptr as *mut c_void);
report
}
}