From 13b68bc693e92378f78f452763a6097bf1755072 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Fri, 31 Jan 2014 12:13:30 -0600 Subject: features/index: Close directories left open on error. Two directory streams are opened, but not always closed if the function exits with an error. This patch aims to ensure that the directories are closed in call cases. Some return values may be explicitly discarded. This is done to avoid having a successful call to closedir() overwrite the value of ret. Also, the errno value is preserved in case a calling function needs to check errno. BUG: 789278 CID: 1124710 CID: 1124711 Change-Id: I6bf3b5c9c6a1ec9a99cc9178243ea98572c2bac2 Signed-off-by: Christopher R. Hertel Reviewed-on: http://review.gluster.org/6883 Reviewed-by: Shyamsundar Ranganathan Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/features/index/src/index.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c index ec395e8a4..5edfeda8f 100644 --- a/xlators/features/index/src/index.c +++ b/xlators/features/index/src/index.c @@ -371,6 +371,7 @@ sync_base_indices (void *index_priv) char xattrop_directory[PATH_MAX] = {0}; char base_index_path[PATH_MAX] = {0}; char xattrop_index_path[PATH_MAX] = {0}; + int32_t op_errno = 0; int ret = 0; priv = index_priv; @@ -381,11 +382,14 @@ sync_base_indices (void *index_priv) XATTROP_SUBDIR); if ((dir_base_holder = opendir(base_indices_holder)) == NULL) { + op_errno = errno; ret = -1; goto out; } if ((xattrop_dir = opendir (xattrop_directory)) == NULL) { + op_errno = errno; ret = -1; + (void) closedir (dir_base_holder); goto out; } @@ -410,20 +414,30 @@ sync_base_indices (void *index_priv) ret = sys_link (xattrop_index_path, base_index_path); - if (ret && errno != EEXIST) + if (ret && errno != EEXIST) { + op_errno = errno; + (void) closedir (dir_base_holder); + (void) closedir (xattrop_dir); goto out; + } } } ret = closedir (xattrop_dir); - if (ret) + if (ret) { + op_errno = errno; + (void) closedir (dir_base_holder); goto out; + } ret = closedir (dir_base_holder); - if (ret) + if (ret) { + op_errno = errno; goto out; + } ret = 0; out: + errno = op_errno; return ret; } -- cgit