Commit 7bf8ed71 authored by Yoni Fogel's avatar Yoni Fogel

[t:5039] Closes #5039 fix memory leaks in ft-serialize-benchmark

git-svn-id: file:///svn/toku/tokudb@44360 c7de825b-a66e-492c-adef-691d508d4ae1
parent 66a0df48
...@@ -55,32 +55,34 @@ static void ...@@ -55,32 +55,34 @@ static void
test_serialize_leaf(int valsize, int nelts, double entropy) { test_serialize_leaf(int valsize, int nelts, double entropy) {
// struct ft_handle source_ft; // struct ft_handle source_ft;
const int nodesize = (1<<22); const int nodesize = (1<<22);
struct ftnode sn, *dn; struct ftnode *sn, *dn;
int fd = open(__SRCFILE__ ".ft", O_RDWR|O_CREAT|O_BINARY, S_IRWXU|S_IRWXG|S_IRWXO); assert(fd >= 0); int fd = open(__SRCFILE__ ".ft", O_RDWR|O_CREAT|O_BINARY, S_IRWXU|S_IRWXG|S_IRWXO); assert(fd >= 0);
int r; int r;
sn.max_msn_applied_to_node_on_disk.msn = 0; XCALLOC(sn);
sn.nodesize = nodesize;
sn.flags = 0x11223344; sn->max_msn_applied_to_node_on_disk.msn = 0;
sn.thisnodename.b = 20; sn->nodesize = nodesize;
sn.layout_version = FT_LAYOUT_VERSION; sn->flags = 0x11223344;
sn.layout_version_original = FT_LAYOUT_VERSION; sn->thisnodename.b = 20;
sn.height = 0; sn->layout_version = FT_LAYOUT_VERSION;
sn.n_children = 8; sn->layout_version_original = FT_LAYOUT_VERSION;
sn.dirty = 1; sn->height = 0;
MALLOC_N(sn.n_children, sn.bp); sn->n_children = 8;
MALLOC_N(sn.n_children-1, sn.childkeys); sn->dirty = 1;
sn.totalchildkeylens = 0; MALLOC_N(sn->n_children, sn->bp);
for (int i = 0; i < sn.n_children; ++i) { MALLOC_N(sn->n_children-1, sn->childkeys);
BP_STATE(&sn,i) = PT_AVAIL; sn->totalchildkeylens = 0;
set_BLB(&sn, i, toku_create_empty_bn()); for (int i = 0; i < sn->n_children; ++i) {
BP_STATE(sn,i) = PT_AVAIL;
set_BLB(sn, i, toku_create_empty_bn());
} }
int nperbn = nelts / sn.n_children; int nperbn = nelts / sn->n_children;
LEAFENTRY les[nelts]; LEAFENTRY les[nelts];
memset(les, 0, sizeof les); memset(les, 0, sizeof les);
for (int ck = 0; ck < sn.n_children; ++ck) { for (int ck = 0; ck < sn->n_children; ++ck) {
long k; long k;
for (long i = 0; i < nperbn; ++i) { for (long i = 0; i < nperbn; ++i) {
k = ck * nperbn + i; k = ck * nperbn + i;
...@@ -93,12 +95,12 @@ test_serialize_leaf(int valsize, int nelts, double entropy) { ...@@ -93,12 +95,12 @@ test_serialize_leaf(int valsize, int nelts, double entropy) {
} }
memset(&buf[c], 0, valsize - c); memset(&buf[c], 0, valsize - c);
les[k] = le_fastmalloc((char *)&k, sizeof k, buf, sizeof buf); les[k] = le_fastmalloc((char *)&k, sizeof k, buf, sizeof buf);
r = toku_omt_insert(BLB_BUFFER(&sn, ck), les[k], omt_cmp, les[k], NULL); assert(r==0); r = toku_omt_insert(BLB_BUFFER(sn, ck), les[k], omt_cmp, les[k], NULL); assert(r==0);
} }
BLB_NBYTESINBUF(&sn, ck) = nperbn*(KEY_VALUE_OVERHEAD+(sizeof(long)+valsize)) + toku_omt_size(BLB_BUFFER(&sn, ck)); BLB_NBYTESINBUF(sn, ck) = nperbn*(KEY_VALUE_OVERHEAD+(sizeof(long)+valsize)) + toku_omt_size(BLB_BUFFER(sn, ck));
if (ck < 7) { if (ck < 7) {
toku_fill_dbt(&sn.childkeys[ck], toku_xmemdup(&k, sizeof k), sizeof k); toku_fill_dbt(&sn->childkeys[ck], toku_xmemdup(&k, sizeof k), sizeof k);
sn.totalchildkeylens += sizeof k; sn->totalchildkeylens += sizeof k;
} }
} }
...@@ -138,7 +140,7 @@ test_serialize_leaf(int valsize, int nelts, double entropy) { ...@@ -138,7 +140,7 @@ test_serialize_leaf(int valsize, int nelts, double entropy) {
struct timeval t[2]; struct timeval t[2];
gettimeofday(&t[0], NULL); gettimeofday(&t[0], NULL);
FTNODE_DISK_DATA ndd = NULL; FTNODE_DISK_DATA ndd = NULL;
r = toku_serialize_ftnode_to(fd, make_blocknum(20), &sn, &ndd, TRUE, brt->ft, 1, 1, FALSE); r = toku_serialize_ftnode_to(fd, make_blocknum(20), sn, &ndd, TRUE, brt->ft, 1, 1, FALSE);
assert(r==0); assert(r==0);
gettimeofday(&t[1], NULL); gettimeofday(&t[1], NULL);
double dt; double dt;
...@@ -157,17 +159,12 @@ test_serialize_leaf(int valsize, int nelts, double entropy) { ...@@ -157,17 +159,12 @@ test_serialize_leaf(int valsize, int nelts, double entropy) {
toku_ftnode_free(&dn); toku_ftnode_free(&dn);
for (int i = 0; i < sn.n_children-1; ++i) {
toku_free(sn.childkeys[i].data);
}
for (int i = 0; i < nelts; ++i) { for (int i = 0; i < nelts; ++i) {
if (les[i]) { toku_free(les[i]); } if (les[i]) {
} toku_free(les[i]);
for (int ck = 0; ck < sn.n_children; ++ck) { }
destroy_basement_node(BLB(&sn, ck));
} }
toku_free(sn.bp); toku_ftnode_free(&sn);
toku_free(sn.childkeys);
toku_block_free(brt_h->blocktable, BLOCK_ALLOCATOR_TOTAL_HEADER_RESERVE); toku_block_free(brt_h->blocktable, BLOCK_ALLOCATOR_TOTAL_HEADER_RESERVE);
toku_blocktable_destroy(&brt_h->blocktable); toku_blocktable_destroy(&brt_h->blocktable);
......
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