mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
#247 fix loader->close fd leak when NOFILE limit exceeded
This commit is contained in:
parent
1d6d6e3ce8
commit
1e9f2f07b9
5 changed files with 20 additions and 28 deletions
|
@ -356,6 +356,8 @@ int ft_loader_open_temp_file (FTLOADER bl, FIDX *file_idx)
|
|||
*/
|
||||
{
|
||||
int result = 0;
|
||||
if (result) // debug hack
|
||||
return result;
|
||||
FILE *f = NULL;
|
||||
int fd = -1;
|
||||
char *fname = toku_strdup(bl->temp_file_template);
|
||||
|
@ -2430,6 +2432,8 @@ static int toku_loader_write_ft_from_q (FTLOADER bl,
|
|||
if (r) {
|
||||
result = r;
|
||||
drain_writer_q(q);
|
||||
r = toku_os_close(fd);
|
||||
assert_zero(r);
|
||||
return result;
|
||||
}
|
||||
FILE *pivots_stream = toku_bl_fidx2file(bl, pivots_file);
|
||||
|
|
|
@ -85,6 +85,9 @@ PATENT RIGHTS GRANT:
|
|||
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 "$Id$"
|
||||
|
||||
|
@ -95,11 +98,7 @@ PATENT RIGHTS GRANT:
|
|||
static int loader_flags = 0;
|
||||
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)) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
static void loader_open_close(int ndb) {
|
||||
static void run_test(int ndb) {
|
||||
int r;
|
||||
|
||||
char rmcmd[32 + strlen(envdir)];
|
||||
|
@ -109,8 +108,6 @@ static void loader_open_close(int ndb) {
|
|||
|
||||
DB_ENV *env;
|
||||
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;
|
||||
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
|
||||
env->set_errfile(env, stderr);
|
||||
|
@ -196,6 +193,6 @@ static void do_args(int argc, char * const argv[]) {
|
|||
|
||||
int test_main(int argc, char * const *argv) {
|
||||
do_args(argc, argv);
|
||||
loader_open_close(1);
|
||||
run_test(1);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -97,11 +97,7 @@ PATENT RIGHTS GRANT:
|
|||
static int loader_flags = 0;
|
||||
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)) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
static void loader_open_abort(int ndb) {
|
||||
static void test_loader_create_close(int ndb) {
|
||||
int r;
|
||||
|
||||
char rmcmd[32 + strlen(envdir)];
|
||||
|
@ -111,8 +107,6 @@ static void loader_open_abort(int ndb) {
|
|||
|
||||
DB_ENV *env;
|
||||
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;
|
||||
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
|
||||
env->set_errfile(env, stderr);
|
||||
|
@ -181,8 +175,8 @@ static void do_args(int argc, char * const argv[]) {
|
|||
|
||||
int test_main(int argc, char * const *argv) {
|
||||
do_args(argc, argv);
|
||||
loader_open_abort(0);
|
||||
loader_open_abort(1);
|
||||
loader_open_abort(2);
|
||||
test_loader_create_close(0);
|
||||
test_loader_create_close(1);
|
||||
test_loader_create_close(2);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ PATENT RIGHTS GRANT:
|
|||
static int loader_flags = 0;
|
||||
static const char *envdir = TOKU_TEST_FILENAME;
|
||||
|
||||
static void loader_create_commit(int ndb) {
|
||||
static void run_test(int ndb) {
|
||||
int r;
|
||||
|
||||
char rmcmd[32 + strlen(envdir)];
|
||||
|
@ -206,6 +206,6 @@ static void do_args(int argc, char * const argv[]) {
|
|||
|
||||
int test_main(int argc, char * const *argv) {
|
||||
do_args(argc, argv);
|
||||
loader_create_commit(1);
|
||||
run_test(1);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,9 @@ PATENT RIGHTS GRANT:
|
|||
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 "$Id$"
|
||||
|
||||
|
@ -95,11 +98,7 @@ PATENT RIGHTS GRANT:
|
|||
static int loader_flags = 0;
|
||||
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)) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
static void loader_open_close(int ndb) {
|
||||
static void run_test(int ndb) {
|
||||
int r;
|
||||
|
||||
char rmcmd[32 + strlen(envdir)];
|
||||
|
@ -109,8 +108,6 @@ static void loader_open_close(int ndb) {
|
|||
|
||||
DB_ENV *env;
|
||||
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;
|
||||
r = env->open(env, envdir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
|
||||
env->set_errfile(env, stderr);
|
||||
|
@ -197,6 +194,6 @@ static void do_args(int argc, char * const argv[]) {
|
|||
|
||||
int test_main(int argc, char * const *argv) {
|
||||
do_args(argc, argv);
|
||||
loader_open_close(1);
|
||||
run_test(1);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue