From 6c4b8d02db7b47d67a306a71a72bcc016fbdf183 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat Date: Wed, 29 Feb 2012 23:23:54 +0530 Subject: 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 Reviewed-on: http://review.gluster.com/2843 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/mgmt/glusterd/src/glusterd-volgen.c | 15 +++++++++++++-- 1 file 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) -- cgit