summaryrefslogtreecommitdiffstats
path: root/api/src
diff options
context:
space:
mode:
authorKaleb S KEITHLEY <kkeithle@redhat.com>2016-05-06 13:04:38 -0400
committerJeff Darcy <jdarcy@redhat.com>2016-06-01 06:50:13 -0700
commit24dd33929bbbc9a72360793048f17bf4e6cec8a3 (patch)
treecaa5c51a587252ff222ae885514a70a19ca05a1d /api/src
parenta04eaf366779a0632e5b9cdd6d63de0eb62f7449 (diff)
libglusterfs (timer): race conditions, illegal mem access, mem leak
While investigating gfapi memory consumption with valgrind, valgrind reported several memory access issues. Also see the timer 'registry' being recreated (shortly) after being freed during teardown due to the way it's currently written. Passing ctx as data to gf_timer_proc() is prone to memory access issues if ctx is freed before gf_timer_proc() terminates. (And in fact this does happen, at least in valgrind.) gf_timer_proc() doesn't need ctx for anything, it only needs ctx->timer, so just pass that. Nothing ever calls gf_timer_registry_init(). Nothing outside of timer.c that is. Making it and gf_timer_proc() static. Change-Id: Ia28454dda0cf0de2fec94d76441d98c3927a906a BUG: 1333925 Signed-off-by: Kaleb S KEITHLEY <kkeithle@redhat.com> Reviewed-on: http://review.gluster.org/14247 NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> Smoke: Gluster Build System <jenkins@build.gluster.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Poornima G <pgurusid@redhat.com> Reviewed-by: Niels de Vos <ndevos@redhat.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'api/src')
-rw-r--r--api/src/glfs.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c
index 0d67ce1a86c..1cb6bf7a3cf 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -149,7 +149,7 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx)
LOCK_INIT (&pool->lock);
ctx->pool = pool;
- pthread_mutex_init (&(ctx->lock), NULL);
+ LOCK_INIT (&ctx->lock);
ret = 0;
err:
@@ -1059,9 +1059,9 @@ glusterfs_ctx_destroy (glusterfs_ctx_t *ctx)
GF_FREE (ctx->process_uuid);
GF_FREE (ctx->cmd_args.volfile_id);
- pthread_mutex_destroy (&(ctx->lock));
- pthread_mutex_destroy (&(ctx->notify_lock));
- pthread_cond_destroy (&(ctx->notify_cond));
+ LOCK_DESTROY (&ctx->lock);
+ pthread_mutex_destroy (&ctx->notify_lock);
+ pthread_cond_destroy (&ctx->notify_cond);
/* Free all the graph structs and its containing xlator_t structs
* from this point there should be no reference to GF_FREE/GF_CALLOC
_cmds[];
int
@@ -61,6 +62,13 @@ cli_cmd_display_help (struct cli_state *state, struct cli_cmd_word *in_word,
for (cmd = cli_probe_cmds; cmd->pattern; cmd++)
cli_out ("%s - %s", cmd->pattern, cmd->desc);
+ /*
+ * commands for internal usage, don't expose
+
+ for (cmd = cli_system_cmds; cmd->pattern; cmd++)
+ cli_out ("%s - %s", cmd->pattern, cmd->desc);
+ */
+
for (cmd = cli_misc_cmds; cmd->pattern; cmd++)
cli_out ("%s - %s", cmd->pattern, cmd->desc);
diff --git a/cli/src/cli-cmd-system.c b/cli/src/cli-cmd-system.c
new file mode 100644
index 00000000000..ec53b9848fb
--- /dev/null
+++ b/cli/src/cli-cmd-system.c
@@ -0,0 +1,80 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <pthread.h>
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "cli.h"
+#include "cli-cmd.h"
+#include "cli-mem-types.h"
+#include "protocol-common.h"
+
+extern struct rpc_clnt *global_rpc;
+
+extern rpc_clnt_prog_t *cli_rpc_prog;
+
+int cli_cmd_system_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
+ const char **words, int wordcount);
+
+struct cli_cmd cli_system_cmds[] = {
+ { "system:: help",
+ cli_cmd_system_help_cbk,
+ "display help for system commands"},
+
+ { NULL, NULL, NULL }
+};
+
+int
+cli_cmd_system_help_cbk (struct cli_state *state, struct cli_cmd_word *in_word,
+ const char **words, int wordcount)
+{
+ struct cli_cmd *cmd = NULL;
+
+ for (cmd = cli_system_cmds; cmd->pattern; cmd++)
+ cli_out ("%s - %s", cmd->pattern, cmd->desc);
+
+ if (!state->rl_enabled)
+ exit (0);
+
+ return 0;
+}
+
+int
+cli_cmd_system_register (struct cli_state *state)
+{
+ int ret = 0;
+ struct cli_cmd *cmd = NULL;
+
+ for (cmd = cli_system_cmds; cmd->pattern; cmd++) {
+ ret = cli_cmd_register (&state->tree, cmd->pattern, cmd->cbk,
+ cmd->desc);
+ if (ret)
+ goto out;
+ }
+out:
+ return ret;
+}
diff --git a/cli/src/cli-cmd.c b/cli/src/cli-cmd.c
index 011edacfe90..f09c6210634 100644
--- a/cli/src/cli-cmd.c
+++ b/cli/src/cli-cmd.c
@@ -199,6 +199,10 @@ cli_cmds_register (struct cli_state *state)
if (ret)
goto out;
+ ret = cli_cmd_system_register (state);
+ if (ret)
+ goto out;
+
ret = cli_cmd_misc_register (state);
if (ret)
goto out;
diff --git a/cli/src/cli-cmd.h b/cli/src/cli-cmd.h
index 7dda509dd0c..89fc44cfaf5 100644
--- a/cli/src/cli-cmd.h
+++ b/cli/src/cli-cmd.h
@@ -49,6 +49,8 @@ int cli_cmd_volume_register (struct cli_state *state);
int cli_cmd_probe_register (struct cli_state *state);
+int cli_cmd_system_register (struct cli_state *state);
+
int cli_cmd_misc_register (struct cli_state *state);
struct cli_cmd_word *cli_cmd_nextword (struct cli_cmd_word *word,