summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher R. Hertel <crh@redhat.com>2014-01-31 12:13:30 -0600
committerVijay Bellur <vbellur@redhat.com>2014-02-07 18:56:54 -0800
commit13b68bc693e92378f78f452763a6097bf1755072 (patch)
treeb1fafa7ed731ae3d299077274607567b32730707
parent38e23d727a8fb5a4d688d9f8dc9178e6718215f5 (diff)
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 <crh@redhat.com> Reviewed-on: http://review.gluster.org/6883 Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r--xlators/features/index/src/index.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
index ec395e8..5edfeda 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;
}