gfapi: prevent mem-pool leak in case glfs_new_fs() fails
Commit 7039243e187 adds a call to mem_pools_init() so that the memory pool cleanup thread ("sweeper") is started. However, now it is possible that users of gfapi can not cleanup this thread because glfs_new() can return NULL, but the sweeper is still running. In case glfs_fs_new() fails, mem_pools_fini() needs to be called as well. This seems more correct than calling mem_pools_init() after glfs_fs_new(), and this makes using memory pools possible *really* early in the gfapi initialization. Change-Id: I1f2fb25cc33e227b3c33ce9d1b03f67bc27e981a Fixes: 7039243e187 ("gfapi: add mem_pools_init and mem_pools_fini calls") BUG: 1468863 Signed-off-by: Niels de Vos <ndevos@redhat.com> Reviewed-on: https://review.gluster.org/17734 Reviewed-by: Jeff Darcy <jeff@pl.atyp.us> Reviewed-by: Vijay Bellur <vbellur@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: soumya k <skoduri@redhat.com> Reviewed-by: Amar Tumballi <amarts@redhat.com>
This commit is contained in:
parent
9ab249130a
commit
a4a417e29c
@ -753,45 +753,54 @@ pub_glfs_new (const char *volname)
|
||||
|
||||
fs = glfs_new_fs (volname);
|
||||
if (!fs)
|
||||
return NULL;
|
||||
goto out;
|
||||
|
||||
ctx = glusterfs_ctx_new ();
|
||||
if (!ctx)
|
||||
goto fini;
|
||||
goto out;
|
||||
|
||||
/* first globals init, for gf_mem_acct_enable_set () */
|
||||
|
||||
ret = glusterfs_globals_init (ctx);
|
||||
if (ret)
|
||||
goto fini;
|
||||
goto out;
|
||||
|
||||
old_THIS = THIS;
|
||||
ret = glfs_init_global_ctx ();
|
||||
if (ret)
|
||||
goto fini;
|
||||
goto out;
|
||||
|
||||
/* then ctx_defaults_init, for xlator_mem_acct_init(THIS) */
|
||||
|
||||
ret = glusterfs_ctx_defaults_init (ctx);
|
||||
if (ret)
|
||||
goto fini;
|
||||
goto out;
|
||||
|
||||
fs->ctx = ctx;
|
||||
|
||||
ret = glfs_set_logging (fs, "/dev/null", 0);
|
||||
if (ret)
|
||||
goto fini;
|
||||
goto out;
|
||||
|
||||
fs->ctx->cmd_args.volfile_id = gf_strdup (volname);
|
||||
if (!(fs->ctx->cmd_args.volfile_id))
|
||||
goto fini;
|
||||
if (!(fs->ctx->cmd_args.volfile_id)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
goto out;
|
||||
ret = 0;
|
||||
|
||||
fini:
|
||||
glfs_fini (fs);
|
||||
fs = NULL;
|
||||
out:
|
||||
if (ret) {
|
||||
if (fs) {
|
||||
glfs_fini (fs);
|
||||
fs = NULL;
|
||||
} else {
|
||||
/* glfs_fini() calls mem_pools_fini() too */
|
||||
mem_pools_fini ();
|
||||
}
|
||||
}
|
||||
|
||||
if (old_THIS)
|
||||
THIS = old_THIS;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user