From 71496826955cacac37abfd5fd017340a04988971 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Wed, 20 Mar 2013 23:01:39 +0530 Subject: glusterfsd: Fixed fd leak due to use of tmpfile() Change-Id: I3c2dc070ebe967100170e39f3545acacc6016d61 BUG: 924075 Signed-off-by: Krishnan Parthasarathi Reviewed-on: http://review.gluster.org/4703 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy --- glusterfsd/src/glusterfsd-mgmt.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'glusterfsd') diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c index 86412efa..d28397a1 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; } -- cgit