diff --git a/db.go b/db.go index d01c6e3..2998be4 100644 --- a/db.go +++ b/db.go @@ -1787,9 +1787,6 @@ func (db *DB) DisableManualCompaction() { } // GetColumnFamilyMetadata returns the metadata of the default column family. -// -// Note that the caller is responsible to release the returned memory -// using rocksdb_column_family_metadata_destroy. func (db *DB) GetColumnFamilyMetadata() (m *ColumnFamilyMetadata) { if c := C.rocksdb_get_column_family_metadata(db.c); c != nil { m = newColumnFamilyMetadata(c) @@ -1798,9 +1795,6 @@ func (db *DB) GetColumnFamilyMetadata() (m *ColumnFamilyMetadata) { } // GetColumnFamilyMetadataCF returns the metadata of the specified column family. -// -// Note that the caller is responsible to release the returned memory -// using rocksdb_column_family_metadata_destroy. func (db *DB) GetColumnFamilyMetadataCF(cf *ColumnFamilyHandle) (m *ColumnFamilyMetadata) { if c := C.rocksdb_get_column_family_metadata_cf(db.c, cf.c); c != nil { m = newColumnFamilyMetadata(c) diff --git a/options.go b/options.go index 0e5ac57..bd93c9f 100644 --- a/options.go +++ b/options.go @@ -1511,9 +1511,9 @@ func (opts *Options) SetFIFOCompactionOptions(value *FIFOCompactionOptions) { // GetStatisticsString returns the statistics as a string. func (opts *Options) GetStatisticsString() (stats string) { - sString := C.rocksdb_options_statistics_get_string(opts.c) - stats = C.GoString(sString) - C.rocksdb_free(unsafe.Pointer(sString)) + cValue := C.rocksdb_options_statistics_get_string(opts.c) + stats = C.GoString(cValue) + C.rocksdb_free(unsafe.Pointer(cValue)) return } diff --git a/transaction.go b/transaction.go index fe3775e..936eb43 100644 --- a/transaction.go +++ b/transaction.go @@ -33,9 +33,9 @@ func (transaction *Transaction) SetName(name string) (err error) { // GetName of transaction. func (transaction *Transaction) GetName() string { - var nameSize C.size_t - name := C.rocksdb_transaction_get_name(transaction.c, &nameSize) - return C.GoString(name) + var len C.size_t + cValue := C.rocksdb_transaction_get_name(transaction.c, &len) + return toString(cValue, C.int(len)) } // Prepare transaction. diff --git a/util.go b/util.go index c3acc70..a61d4ac 100644 --- a/util.go +++ b/util.go @@ -75,3 +75,9 @@ func fromCError(cErr *C.char) (err error) { } return } + +func toString(cVal *C.char, len C.int) string { + s := C.GoStringN(cVal, C.int(len)) + C.rocksdb_free(unsafe.Pointer(cVal)) + return s +}