Commit e10d6bb1 authored by John Esmet's avatar John Esmet Committed by Yoni Fogel

[t:5133] fix a memory leak, clean up the ule API.


git-svn-id: file:///svn/toku/tokudb@45044 c7de825b-a66e-492c-adef-691d508d4ae1
parent 59c8d159
......@@ -77,9 +77,9 @@ toku_le_get_status(LE_STATUS statp) {
//
ULEHANDLE
toku_ule_create(void * le_p) {
toku_ule_create(const LEAFENTRY le) {
ULE ule_p = toku_xmalloc(sizeof(ULE_S));
le_unpack(ule_p, le_p);
le_unpack(ule_p, le);
return (ULEHANDLE) ule_p;
}
......@@ -518,7 +518,7 @@ ule_cleanup(ULE ule) {
// Purpose of le_unpack() is to populate our private workspace with the contents of the given le.
void
le_unpack(ULE ule, LEAFENTRY le) {
le_unpack(ULE ule, const LEAFENTRY le) {
//Read the keylen
ule->keylen = toku_dtoh32(le->keylen);
uint8_t type = le->type;
......
......@@ -23,7 +23,8 @@ extern "C" {
typedef struct ule *ULEHANDLE;
typedef struct uxr *UXRHANDLE;
ULEHANDLE toku_ule_create(void * le_p);
// create a ULE by copying the contents of the given leafentry
ULEHANDLE toku_ule_create(const LEAFENTRY le);
void toku_ule_free(ULEHANDLE ule_p);
......
......@@ -364,16 +364,21 @@ struct le_cursor_extra {
// cachetable pair locks. because no txn can commit on this db, read
// the provisional info for the newly read ule.
static int
le_cursor_callback(ITEMLEN UU(keylen), bytevec UU(key), ITEMLEN vallen, bytevec val, void *extra, bool lock_only) {
le_cursor_callback(ITEMLEN UU(keylen), bytevec UU(key), ITEMLEN UU(vallen), bytevec val, void *extra, bool lock_only) {
if (lock_only || val == NULL) {
; // do nothing if only locking or val==NULL, meaning there are no more elements
; // do nothing if only locking. do nothing if val==NULL, means DB_NOTFOUND
} else {
struct le_cursor_extra *cursor_extra = extra;
struct ule_prov_info *prov_info = cursor_extra->prov_info;
// TODO(John): Do we need to actually copy this ule and save it after
// copying all of the provisional info? or is the info all we need?
void *le_buf = toku_xmemdup(val, vallen);
ULEHANDLE ule = toku_ule_create(le_buf);
// the val here is a leafentry. ule_create copies the contents of a
// leafentry into its own buffers, so we don't need to malloc space
// for this value to exist outside the callback.
//
// this cast is only necssary because the typedef is preventing us
// from declaring a "const LEAFENTRY" le. we're only able to say
// const "LEAFENTRY le".
const LEAFENTRY le = (const LEAFENTRY) val;
ULEHANDLE ule = toku_ule_create(le);
invariant(ule);
ule_prov_info_init(prov_info, ule);
indexer_fill_prov_info(cursor_extra->indexer, prov_info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment