Commit eda78576 authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

start a test on brtloader_open memory leaks refs[t:2591] #2591

git-svn-id: file:///svn/toku/tokudb@20031 c7de825b-a66e-492c-adef-691d508d4ae1
parent 47f2199d
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "$Id: pqueue.c$"
#ident "Copyright (c) 2010 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
// The purpose of this test is to find memory leaks in the brtloader_open function. Right now, it finds leaks in some very simple
// cases.
#define DONT_DEPRECATE_MALLOC
#include "test.h"
#include "brtloader.h"
#include "brtloader-internal.h"
#include "memory.h"
#if defined(__cplusplus)
extern "C" {
#endif
static int my_malloc_count = 0;
static int my_malloc_trigger = 0;
static void set_my_malloc_trigger(int n) {
my_malloc_count = 0;
my_malloc_trigger = n;
}
static void *my_malloc(size_t n) {
my_malloc_count++;
if (my_malloc_count == my_malloc_trigger) {
errno = ENOSPC;
return NULL;
} else
return malloc(n);
}
static void test_loader_open(void) {
int r;
BRTLOADER loader;
toku_set_func_malloc(my_malloc);
int i;
for (i = 0; ; i++) {
set_my_malloc_trigger(i+1);
r = toku_brt_loader_open(&loader, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, "", ZERO_LSN);
if (r == 0)
break;
}
if (verbose) printf("i=%d\n", i);
r = toku_brt_loader_abort(loader, TRUE);
assert(r == 0);
}
int test_main (int argc, const char *argv[]) {
const char *progname=argv[0];
argc--; argv++;
while (argc>0) {
if (strcmp(argv[0],"-v")==0) {
verbose=1;
} else if (strcmp(argv[0],"-q")==0) {
verbose=0;
} else if (argc!=1) {
fprintf(stderr, "Usage:\n %s [-v] [-q]\n", progname);
exit(1);
}
else {
break;
}
argc--; argv++;
}
test_loader_open();
return 0;
}
#if defined(__cplusplus)
}
#endif
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