Commit 7c3c5307 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Get rid of a bunch of valgrind warnings (none of which are real errors, probably)

git-svn-id: file:///svn/tokudb@76 c7de825b-a66e-492c-adef-691d508d4ae1
parent 681e5c89
......@@ -3,18 +3,21 @@
# OPTFLAGS = -O2
CFLAGS = -Wall -W $(OPTFLAGS) -g $(GCOV_FLAGS) $(PROF_FLAGS) -Werror -fPIC
LDFLAGS = $(OPTFLAGS) -g $(GCOV_FLAGS) $(PROF_FLAGS)
DTOOL = valgrind
DTOOL = valgrind --quiet --error-exitcode=1
# When debugging, try: valgrind --show-reachable=yes --leak-check=full ./brt-test
default: bins
BINS = pma-test brt-test cachetable-test brt-serialize-test randbrt randdb4 hashtest ybt-test
bins: $(BINS)
check: bins
$(DTOOL) ./ybt-test
./pma-test
./cachetable-test
./brt-serialize-test
$(DTOOL) ./pma-test
$(DTOOL) ./cachetable-test
$(DTOOL) ./brt-serialize-test
./brt-test
./hashtest
$(DTOOL) ./hashtest
# ./mdict-test
# pma: PROF_FLAGS=-fprofile-arcs -ftest-coverage
......@@ -26,7 +29,7 @@ ybt.o: ybt.h brttypes.h
ybt-test: ybt-test.o ybt.o memory.o
cachetable.o: cachetable.h
brt-test: ybt.o brt.o hashtable.o pma.o memory.o brt-serialize.o cachetable.o header-io.o ybt.o key.o
brt-test.o brt.o: brt.h hashtable.h pma.h brttypes.h
brt-test.o brt.o: brt.h hashtable.h pma.h brttypes.h cachetable.h
brt-serialize-test.o: pma.h yerror.h brt.h memory.h hashtable.h brttypes.h brt-internal.h
brt.o: brt.h mdict.h pma.h brttypes.h memory.h brt-internal.h cachetable.h hashtable.h
mdict.o: pma.h
......@@ -38,7 +41,7 @@ header-io.o: brttypes.h brt-internal.h memory.h
mdict-test: hashtable.o pma.o memory.o
brt-bigtest: memory.o ybt.o brt.o pma.o cachetable.o key.o hashtable.o brt-serialize.o
brt-serialize-test: brt-serialize-test.o brt-serialize.o memory.o hashtable.o pma.o key.o ybt.o
brt-serialize-test: brt-serialize-test.o brt-serialize.o memory.o hashtable.o pma.o key.o ybt.o brt.o cachetable.o
cachetable-test.o: cachetable.h memory.h
cachetable-test: cachetable.o memory.o cachetable-test.o
......
......@@ -80,6 +80,8 @@ void verify_counts(BRTNODE);
int serialize_brt_header_to (int fd, struct brt_header *h);
int deserialize_brtheader_from (int fd, diskoff off, struct brt_header **brth);
void brtnode_free (BRTNODE *node);
//static inline int brtnode_n_hashtables(BRTNODE node) { if (node->height==0) return 1; else return node->u.n.n_children; }
//int write_brt_header (int fd, struct brt_header *header);
......
......@@ -7,18 +7,20 @@
#include <string.h>
void test_serialize(void) {
// struct brt source_brt;
struct brtnode sn,*dn; /* Source node, Dest node */
// struct brt source_brt;
int nodesize = 1024;
struct brtnode sn, *dn;
int fd = open("brt-serialize-test.brt", O_RDWR|O_CREAT, 0777);
int r;
assert(fd>=0);
// source_brt.fd=fd;
sn.nodesize = 1024;
// source_brt.fd=fd;
char *hello_string;
sn.nodesize = nodesize;
sn.thisnodename = sn.nodesize*20;
sn.height = 1;
sn.u.n.n_children = 2;
sn.u.n.childkeys[0] = strdup("hello");
sn.u.n.childkeys[0] = hello_string = toku_strdup("hello");
sn.u.n.childkeylens[0] = 6;
sn.u.n.totalchildkeylens = 6;
sn.u.n.children[0] = sn.nodesize*30;
......@@ -30,17 +32,19 @@ void test_serialize(void) {
r = toku_hash_insert(sn.u.n.htables[1], "x", 2, "xval", 5); assert(r==0);
sn.u.n.n_bytes_in_hashtables = 3*(KEY_VALUE_OVERHEAD+2+5);
deserialize_brtnode_from(fd, nodesize*20, &dn, nodesize);
serialize_brtnode_to(fd, sn.nodesize*20, sn.nodesize, &sn);
deserialize_brtnode_from(fd, sn.nodesize*20, &dn, sn.nodesize);
assert(dn->thisnodename==sn.nodesize*20);
assert(dn->thisnodename==nodesize*20);
assert(dn->height == 1);
assert(dn->u.n.n_children==2);
assert(strcmp(dn->u.n.childkeys[0], "hello")==0);
assert(dn->u.n.childkeylens[0]==6);
assert(dn->u.n.totalchildkeylens==6);
assert(dn->u.n.children[0]==sn.nodesize*30);
assert(dn->u.n.children[1]==sn.nodesize*35);
assert(dn->u.n.children[0]==nodesize*30);
assert(dn->u.n.children[1]==nodesize*35);
{
bytevec data; ITEMLEN datalen;
int r = toku_hash_find(dn->u.n.htables[0], "a", 2, &data, &datalen);
......@@ -59,6 +63,11 @@ void test_serialize(void) {
assert(datalen==5);
}
brtnode_free(&dn);
toku_free(hello_string);
toku_hashtable_free(&sn.u.n.htables[0]);
toku_hashtable_free(&sn.u.n.htables[1]);
}
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
......
......@@ -30,7 +30,7 @@ static void test0 (void) {
printf("%s:%d n_items_malloced=%lld\n", __FILE__, __LINE__, n_items_malloced);
r = close_brt(t); assert(r==0);
printf("%s:%d n_items_malloced=%lld\n", __FILE__, __LINE__, n_items_malloced); assert(r==0);
r = cachetable_close(ct);
r = cachetable_close(&ct);
assert(r==0);
memory_check_all_free();
}
......@@ -56,7 +56,7 @@ static void test1 (void) {
assert(v.size==6);
}
r = close_brt(t); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
printf("test1 ok\n");
}
......@@ -94,7 +94,7 @@ static void test2 (int memcheck) {
}
printf("%s:%d inserted\n", __FILE__, __LINE__);
r = close_brt(t); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
printf("test2 ok\n");
}
......@@ -121,7 +121,7 @@ static void test3 (int nodesize, int count, int memcheck) {
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), 0);
}
r = close_brt(t); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
gettimeofday(&t1, 0);
{
......@@ -152,7 +152,7 @@ static void test4 (int nodesize, int count, int memcheck) {
brt_insert(t, fill_dbt(&k, key, 1+strlen(key)), fill_dbt(&v, val, 1+strlen(val)), 0);
}
r = close_brt(t); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
gettimeofday(&t1, 0);
{
......@@ -204,7 +204,7 @@ static void test5 (void) {
printf("\n");
toku_free(values);
r = close_brt(t); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
}
......@@ -221,7 +221,7 @@ static void test_dump_empty_db (void) {
assert(r==0);
dump_brt(t);
r = close_brt(t); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
}
......@@ -256,7 +256,7 @@ static void test_multiple_files_of_size (int size) {
r = close_brt(t0); assert(r==0);
r = close_brt(t1); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
/* Now see if the data is all there. */
......@@ -284,7 +284,7 @@ static void test_multiple_files_of_size (int size) {
r = close_brt(t0); assert(r==0);
r = close_brt(t1); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
}
......@@ -312,7 +312,7 @@ static void test_named_db (void) {
brt_insert(t0, fill_dbt(&k, "good", 5), fill_dbt(&v, "day", 4), 0); assert(r==0);
r = close_brt(t0); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
memory_check_all_free();
......@@ -327,7 +327,7 @@ static void test_named_db (void) {
}
r = close_brt(t0); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
}
......@@ -351,7 +351,7 @@ static void test_multiple_dbs (void) {
r = close_brt(t0); assert(r==0);
r = close_brt(t1); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
......@@ -379,7 +379,7 @@ static void test_multiple_dbs (void) {
r = close_brt(t0); assert(r==0);
r = close_brt(t1); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
printf("ok\n");
......@@ -412,7 +412,7 @@ static void test_multiple_dbs_many (void) {
for (i=0; i<MANYN; i++) {
r = close_brt(trees[i]); assert(r==0);
}
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
}
......@@ -451,7 +451,7 @@ static void test_multiple_brts_one_db_one_file (void) {
for (i=0; i<MANYN; i++) {
r=close_brt(trees[i]); assert(r==0);
}
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
printf(" ok\n");
}
......@@ -474,7 +474,7 @@ static void test_read_what_was_written (void) {
r = brt_create_cachetable(&ct, 0); assert(r==0);
r = open_brt(n, 0, 1, &brt, 1<<12, ct, default_compare_fun); assert(r==0);
r = close_brt(brt); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
......@@ -486,7 +486,7 @@ static void test_read_what_was_written (void) {
brt_insert(brt, fill_dbt(&k, "hello", 6), fill_dbt(&v, "there", 6), 0);
r = close_brt(brt); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
......@@ -561,7 +561,7 @@ static void test_read_what_was_written (void) {
r = close_brt(brt); assert(r==0);
printf("%s:%d About to close %p\n", __FILE__, __LINE__, ct);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
......@@ -588,7 +588,7 @@ static void test_read_what_was_written (void) {
}
r = close_brt(brt); assert(r==0);
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
......@@ -627,7 +627,7 @@ void test_cursor_last_empty(void) {
assert(r==DB_NOTFOUND);
r = close_brt(brt);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
memory_check_all_free();
}
......@@ -677,7 +677,7 @@ void test_cursor_next (void) {
r = close_brt(brt);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
memory_check_all_free();
......@@ -805,7 +805,7 @@ static void test_wrongendian_compare (int wrong_p, unsigned int N) {
r = close_brt(brt);
}
r = cachetable_close(ct); assert(r==0);
r = cachetable_close(&ct); assert(r==0);
memory_check_all_free();
}
......
......@@ -38,7 +38,8 @@
extern long long n_items_malloced;
/* Frees a node, including all the stuff in the hash table. */
void brtnode_free (BRTNODE node) {
void brtnode_free (BRTNODE *nodep) {
BRTNODE node=*nodep;
int i;
//printf("%s:%d %p->mdict[0]=%p\n", __FILE__, __LINE__, node, node->mdicts[0]);
if (node->height>0) {
......@@ -55,6 +56,7 @@ void brtnode_free (BRTNODE node) {
pma_free(&node->u.l.buffer);
}
toku_free(node);
*nodep=0;
}
void brtnode_flush_callback (CACHEFILE cachefile, diskoff nodename, void *brtnode_v, int write_me, int keep_me) {
......@@ -71,7 +73,7 @@ void brtnode_flush_callback (CACHEFILE cachefile, diskoff nodename, void *brtnod
}
//printf("%s:%d %p->mdict[0]=%p\n", __FILE__, __LINE__, brtnode, brtnode->mdicts[0]);
if (!keep_me) {
brtnode_free(brtnode);
brtnode_free(&brtnode);
}
//printf("%s:%d n_items_malloced=%lld\n", __FILE__, __LINE__, n_items_malloced);
}
......@@ -979,7 +981,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
t->compare_fun = compare_fun;
t->skey = t->sval = 0;
if (dbname) {
malloced_name = mystrdup(dbname);
malloced_name = toku_strdup(dbname);
if (malloced_name==0) {
r = ENOMEM;
if (0) { died0a: if(malloced_name) toku_free(malloced_name); }
......@@ -989,7 +991,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
t->database_name = malloced_name;
r=cachetable_openf(&t->cf, cachetable, fname, O_RDWR | (is_create ? O_CREAT : 0), 0777);
if (r!=0) {
if (0) { died1: cachefile_close(t->cf); }
if (0) { died1: cachefile_close(&t->cf); }
goto died0a;
}
assert(nodesize>0);
......@@ -1012,7 +1014,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
t->h->n_named_roots = 1;
if ((MALLOC_N(1, t->h->names))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died3: toku_free(t->h->names); } goto died2; }
if ((MALLOC_N(1, t->h->roots))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died4: toku_free(t->h->roots); } goto died3; }
if ((t->h->names[0] = mystrdup(dbname))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died5: toku_free(t->h->names[0]); } goto died4; }
if ((t->h->names[0] = toku_strdup(dbname))==0) { assert(errno==ENOMEM); r=ENOMEM; if (0) { died5: toku_free(t->h->names[0]); } goto died4; }
t->h->roots[0] = nodesize;
} else {
t->h->unnamed_root = nodesize;
......@@ -1036,7 +1038,7 @@ int open_brt (const char *fname, const char *dbname, int is_create, BRT *newbrt,
if ((t->h->names = toku_realloc(t->h->names, (1+t->h->n_named_roots)*sizeof(*t->h->names))) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; }
if ((t->h->roots = toku_realloc(t->h->roots, (1+t->h->n_named_roots)*sizeof(*t->h->roots))) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; }
t->h->n_named_roots++;
if ((t->h->names[t->h->n_named_roots-1] = mystrdup(dbname)) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; }
if ((t->h->names[t->h->n_named_roots-1] = toku_strdup(dbname)) == 0) { assert(errno==ENOMEM); r=ENOMEM; goto died1; }
printf("%s:%d t=%p\n", __FILE__, __LINE__, t);
t->h->roots[t->h->n_named_roots-1] = malloc_diskblock_header_is_in_memory(t, t->h->nodesize);
if ((r=setup_brt_root_node(t, t->h->roots[t->h->n_named_roots-1]))!=0) goto died1;
......@@ -1076,7 +1078,7 @@ int close_brt (BRT brt) {
}
assert(0==cachefile_count_pinned(brt->cf, 1));
printf("%s:%d closing cachetable\n", __FILE__, __LINE__);
if ((r = cachefile_close(brt->cf))!=0) return r;
if ((r = cachefile_close(&brt->cf))!=0) return r;
if (brt->database_name) toku_free(brt->database_name);
if (brt->skey) { toku_free(brt->skey); }
if (brt->sval) { toku_free(brt->sval); }
......
......@@ -164,9 +164,9 @@ void test0 (void) {
expectN(7);
expectN(6);
expectN(1);
r=cachefile_close(f);
r=cachefile_close(&f);
assert(r==0);
r=cachetable_close(t);
r=cachetable_close(&t);
assert(r==0);
assert(expect_n_flushes==0);
expect_f = 0;
......@@ -215,6 +215,9 @@ void test_nested_pin (void) {
r = cachetable_put(f, 2, &i1, flush_n, fetch_n, f2);
assert(r==0); // now it is unpinned, we can put it.
r = cachefile_close(&f); assert(r==0);
r = cachetable_close(&t); assert(r==0);
}
......@@ -266,6 +269,10 @@ void test_multi_filehandles (void) {
r = cachetable_maybe_get_and_pin(f1, 2, &v); assert(r==0);
assert((unsigned long)v==125);
r = cachefile_close(&f1); assert(r==0);
r = cachefile_close(&f2); assert(r==0);
r = cachefile_close(&f3); assert(r==0);
r = cachetable_close(&t); assert(r==0);
}
int main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
......
......@@ -112,7 +112,8 @@ CACHEFILE remove_cf_from_list (CACHEFILE cf, CACHEFILE list) {
int cachefile_flush (CACHEFILE cf);
int cachefile_close (CACHEFILE cf) {
int cachefile_close (CACHEFILE *cfp) {
CACHEFILE cf = *cfp;
assert(cf->refcount>0);
cf->refcount--;
if (cf->refcount==0) {
......@@ -121,8 +122,10 @@ int cachefile_close (CACHEFILE cf) {
r = close(cf->fd);
cf->cachetable->cachefiles = remove_cf_from_list(cf, cf->cachetable->cachefiles);
toku_free(cf);
*cfp=0;
return r;
} else {
*cfp=0;
return 0;
}
}
......@@ -395,7 +398,8 @@ int cachefile_flush (CACHEFILE cf) {
/* Require that it all be flushed. */
int cachetable_close (CACHETABLE t) {
int cachetable_close (CACHETABLE *tp) {
CACHETABLE t=*tp;
int i;
int r;
if ((r=cachetable_flush(t))) return r;
......@@ -404,6 +408,7 @@ int cachetable_close (CACHETABLE t) {
}
toku_free(t->table);
toku_free(t);
*tp = 0;
return 0;
}
......
......@@ -45,9 +45,9 @@ int cachetable_assert_all_unpinned (CACHETABLE);
int cachefile_count_pinned (CACHEFILE, int /*printthem*/ );
//int cachetable_fsync_all (CACHETABLE); /* Flush everything to disk, but keep it in cache. */
int cachetable_close (CACHETABLE); /* Flushes everything to disk, and destroys the cachetable. */
int cachetable_close (CACHETABLE*); /* Flushes everything to disk, and destroys the cachetable. */
int cachefile_close (CACHEFILE);
int cachefile_close (CACHEFILE*);
//int cachefile_flush (CACHEFILE); /* Flush everything related to the VOID* to disk and free all memory. Don't destroy the cachetable. */
// Return on success (different from pread and pwrite)
......
......@@ -172,7 +172,7 @@ void *memdup (const void *v, unsigned int len) {
memcpy(r,v,len);
return r;
}
char *mystrdup (const char *s) {
char *toku_strdup (const char *s) {
return memdup(s, strlen(s)+1);
}
......
......@@ -13,7 +13,7 @@ void *toku_realloc(void *, long size);
#define TAGMALLOC(t,v) t v = tagmalloc(sizeof(*v), TYP_ ## t);
void *memdup (const void *v, unsigned int len);
char *mystrdup (const char *s);
char *toku_strdup (const char *s);
void memory_check_all_free (void);
void do_memory_check(void);
......
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