summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
diff options
context:
space:
mode:
authorShyamsundarR <srangana@redhat.com>2018-07-26 13:32:52 -0400
committerAmar Tumballi <amarts@redhat.com>2018-07-27 09:06:09 +0000
commit405c6e8a8a64f29b37c154091e1677ef67440e73 (patch)
treef1152850ed93c05d8b323e1e6f9167678234add9 /xlators/mgmt/glusterd/src/glusterd-svc-helper.c
parent46a2cbfb73f7fade3426fd07c5830e9fac82883c (diff)
stack: Reduce stack usage for local variables to store tmpfile names
This patch moves stack based PATH_MAX allocations for tmpfile names, to heap allocated names instead. Reducing the impact on stack space used and accruing benefits thereof. Change-Id: I646d9cb091018de6768b3523902788fa2ba14d96 Updates: bz#1193929 Signed-off-by: ShyamsundarR <srangana@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-svc-helper.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-svc-helper.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-svc-helper.c b/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
index abf979eada5..40726dbfb3e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
+++ b/xlators/mgmt/glusterd/src/glusterd-svc-helper.c
@@ -162,7 +162,7 @@ glusterd_svc_check_volfile_identical (char *svc_name,
gf_boolean_t *identical)
{
char orgvol[PATH_MAX] = {0,};
- char tmpvol[PATH_MAX] = {0,};
+ char *tmpvol = NULL;
glusterd_conf_t *conf = NULL;
xlator_t *this = NULL;
int ret = -1;
@@ -178,7 +178,10 @@ glusterd_svc_check_volfile_identical (char *svc_name,
glusterd_svc_build_volfile_path (svc_name, conf->workdir,
orgvol, sizeof (orgvol));
- snprintf (tmpvol, sizeof (tmpvol), "/tmp/g%s-XXXXXX", svc_name);
+ ret = gf_asprintf(&tmpvol, "/tmp/g%s-XXXXXX", svc_name);
+ if (ret < 0) {
+ goto out;
+ }
/* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
tmp_fd = mkstemp (tmpvol);
@@ -186,6 +189,7 @@ glusterd_svc_check_volfile_identical (char *svc_name,
gf_msg (this->name, GF_LOG_WARNING, errno,
GD_MSG_FILE_OP_FAILED, "Unable to create temp file"
" %s:(%s)", tmpvol, strerror (errno));
+ ret = -1;
goto out;
}
@@ -196,11 +200,13 @@ glusterd_svc_check_volfile_identical (char *svc_name,
goto out;
ret = glusterd_check_files_identical (orgvol, tmpvol, identical);
-
out:
if (need_unlink)
sys_unlink (tmpvol);
+ if (tmpvol != NULL)
+ GF_FREE(tmpvol);
+
if (tmp_fd >= 0)
sys_close (tmp_fd);
@@ -213,7 +219,7 @@ glusterd_svc_check_topology_identical (char *svc_name,
gf_boolean_t *identical)
{
char orgvol[PATH_MAX] = {0,};
- char tmpvol[PATH_MAX] = {0,};
+ char *tmpvol = NULL;
glusterd_conf_t *conf = NULL;
xlator_t *this = THIS;
int ret = -1;
@@ -231,13 +237,18 @@ glusterd_svc_check_topology_identical (char *svc_name,
orgvol, sizeof (orgvol));
/* Create the temporary volfile */
- snprintf (tmpvol, sizeof (tmpvol), "/tmp/g%s-XXXXXX", svc_name);
+ ret = gf_asprintf(&tmpvol, "/tmp/g%s-XXXXXX", svc_name);
+ if (ret < 0) {
+ goto out;
+ }
+
/* coverity[secure_temp] mkstemp uses 0600 as the mode and is safe */
tmpfd = mkstemp (tmpvol);
if (tmpfd < 0) {
gf_msg (this->name, GF_LOG_WARNING, errno,
GD_MSG_FILE_OP_FAILED, "Unable to create temp file"
" %s:(%s)", tmpvol, strerror (errno));
+ ret = -1;
goto out;
}
@@ -256,5 +267,7 @@ out:
sys_close (tmpfd);
if (tmpclean)
sys_unlink (tmpvol);
+ if (tmpvol != NULL)
+ GF_FREE(tmpvol);
return ret;
}