summaryrefslogtreecommitdiffstats
path: root/glusterfsd/src/glusterfsd-mgmt.c
diff options
context:
space:
mode:
authorKrishnan Parthasarathi <kparthas@redhat.com>2013-03-20 23:01:39 +0530
committerAnand Avati <avati@redhat.com>2013-03-22 13:34:29 -0700
commit71496826955cacac37abfd5fd017340a04988971 (patch)
tree93ab5aaa9896a680aa13969d19fe15c0f5b196a5 /glusterfsd/src/glusterfsd-mgmt.c
parente0e34d04aa68ac154818b55e7c337607fb141971 (diff)
glusterfsd: Fixed fd leak due to use of tmpfile()
Change-Id: I3c2dc070ebe967100170e39f3545acacc6016d61 BUG: 924075 Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-on: http://review.gluster.org/4703 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'glusterfsd/src/glusterfsd-mgmt.c')
-rw-r--r--glusterfsd/src/glusterfsd-mgmt.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
index 86412efaffa..d28397a1730 100644
--- a/glusterfsd/src/glusterfsd-mgmt.c
+++ b/glusterfsd/src/glusterfsd-mgmt.c
@@ -1408,14 +1408,21 @@ glusterfs_volfile_reconfigure (FILE *newvolfile_fp)
{
glusterfs_graph_t *oldvolfile_graph = NULL;
glusterfs_graph_t *newvolfile_graph = NULL;
+ int oldvolfile_fd = -1;
FILE *oldvolfile_fp = NULL;
glusterfs_ctx_t *ctx = NULL;
+ char template[PATH_MAX] = {0};
int ret = -1;
- oldvolfile_fp = tmpfile ();
- if (!oldvolfile_fp)
+ strcpy (template, "/tmp/tmp.XXXXXX");
+ oldvolfile_fd = mkstemp (template);
+ oldvolfile_fp = fdopen (oldvolfile_fd, "w+b");
+ if (!oldvolfile_fp) {
+ gf_log ("glusterfsd-mgmt", GF_LOG_CRITICAL, "Failed to create "
+ "temporary volfile");
goto out;
+ }
if (!oldvollen) {
ret = 1; // Has to call INIT for the whole graph
@@ -1472,9 +1479,14 @@ glusterfs_volfile_reconfigure (FILE *newvolfile_fp)
ret = 0;
out:
- if (oldvolfile_fp)
+ if (oldvolfile_fp) {
fclose (oldvolfile_fp);
+ } else if (-1 != oldvolfile_fd) {
+ close (oldvolfile_fd);
+
+ }
+
return ret;
}