From 3e916a283a6c99cecfcafcc392fe2186d6209d66 Mon Sep 17 00:00:00 2001 From: Peter Us Date: Thu, 9 Nov 2023 06:33:26 +0100 Subject: [PATCH] Fix memory leak in new column family metadata (#129) --- cf_metadata.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cf_metadata.go b/cf_metadata.go index dfabc14..aa67d9a 100644 --- a/cf_metadata.go +++ b/cf_metadata.go @@ -2,6 +2,7 @@ package grocksdb // #include "rocksdb/c.h" import "C" +import "unsafe" // ColumnFamilyMetadata contains metadata info of column family. type ColumnFamilyMetadata struct { @@ -98,10 +99,12 @@ func sstMetas(c *C.rocksdb_level_metadata_t) []SstMetadata { var ln C.size_t sk := C.rocksdb_sst_file_metadata_get_smallestkey(sm, &ln) - metas[i].smallestKey = charToByte(sk, ln) + metas[i].smallestKey = C.GoBytes(unsafe.Pointer(sk), C.int(ln)) + C.rocksdb_free(unsafe.Pointer(sk)) sk = C.rocksdb_sst_file_metadata_get_largestkey(sm, &ln) - metas[i].largestKey = charToByte(sk, ln) + metas[i].largestKey = C.GoBytes(unsafe.Pointer(sk), C.int(ln)) + C.rocksdb_free(unsafe.Pointer(sk)) C.rocksdb_sst_file_metadata_destroy(sm) }