rc=TBTIterate(db, &iterator, key, value);
+ if ( key->value ) {
+ char * ptr;
+
+ ptr = tmalloc( key->length );
+ memcpy( ptr, key->value, key->length );
+ key->value = ptr;
+
+ ptr = tmalloc( value->length );
+ memcpy( ptr, value->value, value->length );
+ value->value = ptr;
+ }
+
TBTFreeIterator(db, &iterator);
return rc;
page->islocked=1;
if ( page->page.isleaf ) {
ptr = (TBTPointer*)(page->page.data + db->pointersize * (page->page.npointer-1));
- if ( db->keylen ) {
- key->length = db->keylen;
- key->value = ptr->key.fixed.key;
- } else {
- key->length = ptr->key.varlen.length;
- key->value = page->page.data + ptr->key.varlen.offset;
- }
- value->length = ptr->pointer.leaf.length;
- value->value = page->page.data + ptr->pointer.leaf.offset;
+ key->length = ( db->keylen ) ? db->keylen : ptr->key.varlen.length;
+ key->value = tmalloc( key->length );
+ memcpy( key->value, ( db->keylen ) ? ptr->key.fixed.key : page->page.data + ptr->key.varlen.offset, key->length );
+
+ value->length = ptr->pointer.leaf.length;
+ value->value = tmalloc( value->length );
+ memcpy( value->value, page->page.data + ptr->pointer.leaf.offset, value->length );
} else {
for(i=page->page.npointer-1; i>=0; i--) {
ptr = (TBTPointer*)( page->page.data + db->pointersize * i );
TBTGetLast(TBTree *db, TBTValue *key, TBTValue *value) {
memset(key, 0, sizeof(TBTValue));
memset(value, 0, sizeof(TBTValue));
- return findLast(db, key, value, TBTPAGEROOT);
+ return findLast(db, key, value, TBTPAGEROOT);
}