Commit cd8db79b authored by Rich Prohaska's avatar Rich Prohaska

#247 fix loader->close fd leak when NOFILE limit exceeded

parent 8276c593
...@@ -356,6 +356,8 @@ int ft_loader_open_temp_file (FTLOADER bl, FIDX *file_idx) ...@@ -356,6 +356,8 @@ int ft_loader_open_temp_file (FTLOADER bl, FIDX *file_idx)
*/ */
{ {
int result = 0; int result = 0;
if (result) // debug hack
return result;
FILE *f = NULL; FILE *f = NULL;
int fd = -1; int fd = -1;
char *fname = toku_strdup(bl->temp_file_template); char *fname = toku_strdup(bl->temp_file_template);
...@@ -2430,6 +2432,8 @@ static int toku_loader_write_ft_from_q (FTLOADER bl, ...@@ -2430,6 +2432,8 @@ static int toku_loader_write_ft_from_q (FTLOADER bl,
if (r) { if (r) {
result = r; result = r;
drain_writer_q(q); drain_writer_q(q);
r = toku_os_close(fd);
assert_zero(r);
return result; return result;
} }
FILE *pivots_stream = toku_bl_fidx2file(bl, pivots_file); FILE *pivots_stream = toku_bl_fidx2file(bl, pivots_file);
......
...@@ -97,11 +97,7 @@ PATENT RIGHTS GRANT: ...@@ -97,11 +97,7 @@ PATENT RIGHTS GRANT:
static int loader_flags = 0; static int loader_flags = 0;
static const char *envdir = TOKU_TEST_FILENAME; static const char *envdir = TOKU_TEST_FILENAME;
static int put_multiple_generate(DB *UU(dest_db), DB *UU(src_db), DBT_ARRAY *UU(dest_keys), DBT_ARRAY *UU(dest_vals), const DBT *UU(src_key), const DBT *UU(src_val)) { static void test_loader_create_close(int ndb) {
return ENOMEM;
}
static void loader_open_abort(int ndb) {
int r; int r;
char rmcmd[32 + strlen(envdir)]; char rmcmd[32 + strlen(envdir)];
...@@ -111,8 +107,6 @@ static void loader_open_abort(int ndb) { ...@@ -111,8 +107,6 @@ static void loader_open_abort(int ndb) {
DB_ENV *env; DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r); r = db_env_create(&env, 0); CKERR(r);
r = env->set_generate_row_callback_for_put(env, put_multiple_generate);
CKERR(r);
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE; int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr); env->set_errfile(env, stderr);
...@@ -181,8 +175,8 @@ static void do_args(int argc, char * const argv[]) { ...@@ -181,8 +175,8 @@ static void do_args(int argc, char * const argv[]) {
int test_main(int argc, char * const *argv) { int test_main(int argc, char * const *argv) {
do_args(argc, argv); do_args(argc, argv);
loader_open_abort(0); test_loader_create_close(0);
loader_open_abort(1); test_loader_create_close(1);
loader_open_abort(2); test_loader_create_close(2);
return 0; return 0;
} }
...@@ -95,7 +95,7 @@ PATENT RIGHTS GRANT: ...@@ -95,7 +95,7 @@ PATENT RIGHTS GRANT:
static int loader_flags = 0; static int loader_flags = 0;
static const char *envdir = TOKU_TEST_FILENAME; static const char *envdir = TOKU_TEST_FILENAME;
static void loader_create_commit(int ndb) { static void run_test(int ndb) {
int r; int r;
char rmcmd[32 + strlen(envdir)]; char rmcmd[32 + strlen(envdir)];
...@@ -202,6 +202,6 @@ static void do_args(int argc, char * const argv[]) { ...@@ -202,6 +202,6 @@ static void do_args(int argc, char * const argv[]) {
int test_main(int argc, char * const *argv) { int test_main(int argc, char * const *argv) {
do_args(argc, argv); do_args(argc, argv);
loader_create_commit(1); run_test(1);
return 0; return 0;
} }
...@@ -85,6 +85,9 @@ PATENT RIGHTS GRANT: ...@@ -85,6 +85,9 @@ PATENT RIGHTS GRANT:
under this License. under this License.
*/ */
// Verify that loader->close works correctly (does not crash, does not leak memory, returns the right error code)
// when the NPROC limit is exceeded.
#ident "Copyright (c) 2010-2013 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2010-2013 Tokutek Inc. All rights reserved."
#ident "$Id$" #ident "$Id$"
...@@ -95,11 +98,7 @@ PATENT RIGHTS GRANT: ...@@ -95,11 +98,7 @@ PATENT RIGHTS GRANT:
static int loader_flags = 0; static int loader_flags = 0;
static const char *envdir = TOKU_TEST_FILENAME; static const char *envdir = TOKU_TEST_FILENAME;
static int put_multiple_generate(DB *UU(dest_db), DB *UU(src_db), DBT_ARRAY *UU(dest_keys), DBT_ARRAY *UU(dest_vals), const DBT *UU(src_key), const DBT *UU(src_val)) { static void run_test(int ndb) {
return ENOMEM;
}
static void loader_open_close(int ndb) {
int r; int r;
char rmcmd[32 + strlen(envdir)]; char rmcmd[32 + strlen(envdir)];
...@@ -109,8 +108,6 @@ static void loader_open_close(int ndb) { ...@@ -109,8 +108,6 @@ static void loader_open_close(int ndb) {
DB_ENV *env; DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r); r = db_env_create(&env, 0); CKERR(r);
r = env->set_generate_row_callback_for_put(env, put_multiple_generate);
CKERR(r);
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE; int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr); env->set_errfile(env, stderr);
...@@ -196,6 +193,6 @@ static void do_args(int argc, char * const argv[]) { ...@@ -196,6 +193,6 @@ static void do_args(int argc, char * const argv[]) {
int test_main(int argc, char * const *argv) { int test_main(int argc, char * const *argv) {
do_args(argc, argv); do_args(argc, argv);
loader_open_close(1); run_test(1);
return 0; return 0;
} }
...@@ -85,6 +85,9 @@ PATENT RIGHTS GRANT: ...@@ -85,6 +85,9 @@ PATENT RIGHTS GRANT:
under this License. under this License.
*/ */
// Verify that env->create_loader works correctly (does not crash, does not leak memory, returns the right error code)
// when the NPROC limit is exceeded.
#ident "Copyright (c) 2010-2013 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2010-2013 Tokutek Inc. All rights reserved."
#ident "$Id$" #ident "$Id$"
...@@ -95,11 +98,7 @@ PATENT RIGHTS GRANT: ...@@ -95,11 +98,7 @@ PATENT RIGHTS GRANT:
static int loader_flags = 0; static int loader_flags = 0;
static const char *envdir = TOKU_TEST_FILENAME; static const char *envdir = TOKU_TEST_FILENAME;
static int put_multiple_generate(DB *UU(dest_db), DB *UU(src_db), DBT_ARRAY *UU(dest_keys), DBT_ARRAY *UU(dest_vals), const DBT *UU(src_key), const DBT *UU(src_val)) { static void run_test(int ndb) {
return ENOMEM;
}
static void loader_open_close(int ndb) {
int r; int r;
char rmcmd[32 + strlen(envdir)]; char rmcmd[32 + strlen(envdir)];
...@@ -109,8 +108,6 @@ static void loader_open_close(int ndb) { ...@@ -109,8 +108,6 @@ static void loader_open_close(int ndb) {
DB_ENV *env; DB_ENV *env;
r = db_env_create(&env, 0); CKERR(r); r = db_env_create(&env, 0); CKERR(r);
r = env->set_generate_row_callback_for_put(env, put_multiple_generate);
CKERR(r);
int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE; int envflags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_CREATE | DB_PRIVATE;
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
env->set_errfile(env, stderr); env->set_errfile(env, stderr);
...@@ -197,6 +194,6 @@ static void do_args(int argc, char * const argv[]) { ...@@ -197,6 +194,6 @@ static void do_args(int argc, char * const argv[]) {
int test_main(int argc, char * const *argv) { int test_main(int argc, char * const *argv) {
do_args(argc, argv); do_args(argc, argv);
loader_open_close(1); run_test(1);
return 0; return 0;
} }
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