summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendrabhat@gluster.com>2012-02-29 23:23:54 +0530
committerVijay Bellur <vijay@gluster.com>2012-02-29 21:36:16 -0800
commit6c4b8d02db7b47d67a306a71a72bcc016fbdf183 (patch)
tree16d8aba53fc25be319125c31dbb6db092e4ebefc /xlators/mgmt
parent70fb696abd6144199bc08b05d403daaca314c7b4 (diff)
mgmt/glusterd: do not close the same fd twice
In volfile generation part, if the close on the file stream for the volfile fails, then we should not again close the same file stream which may lead to undefined behavior. Change-Id: Idec00955eea11d5b2ea74574f8d4e53fa80c220a BUG: 798599 Signed-off-by: Raghavendra Bhat <raghavendrabhat@gluster.com> Reviewed-on: http://review.gluster.com/2843 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/mgmt')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 96df8585f65..84222136c81 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -1183,10 +1183,21 @@ volgen_write_volfile (volgen_graph_t *graph, char *filename)
goto error;
if (glusterfs_graph_print_file (f, &graph->graph) == -1)
- goto error;
+ goto error;
- if (fclose (f) == -1)
+ if (fclose (f) != 0) {
+ gf_log (THIS->name, GF_LOG_ERROR, "fclose on the file %s "
+ "failed (%s)", ftmp, strerror (errno));
+ /*
+ * Even though fclose has failed here, we have to set f to NULL.
+ * Otherwise when the code path goes to error, there again we
+ * try to close it which might cause undefined behavior such as
+ * process crash.
+ */
+ f = NULL;
goto error;
+ }
+
f = NULL;
if (rename (ftmp, filename) == -1)