git » libjio » commit c736bd4

Try to close as much as possible in jclose(). Thanks to Pieter Grimmerink for the suggestion.

author Alberto Bertogli
2004-08-29 00:22:53 UTC
committer Alberto Bertogli
2007-07-15 13:17:15 UTC
parent e4d35a3f2f33affc4875edc5ff499e84d014b82e

Try to close as much as possible in jclose(). Thanks to Pieter Grimmerink for the suggestion.

Try to close as much as possible in jclose().
Thanks to Pieter Grimmerink for the suggestion.

trans.c +12 -5

diff --git a/trans.c b/trans.c
index 73ced6a..3f7e40e 100644
--- a/trans.c
+++ b/trans.c
@@ -606,20 +606,27 @@ exit:
 /* close a file */
 int jclose(struct jfs *fs)
 {
+	int ret;
+
+	ret = 0;
+	pthread_mutex_lock(&(fs->lock));
+
 	if (jsync(fs))
-		return -1;
+		ret = -1;
 	if (close(fs->fd))
-		return -1;
+		ret = -1;
 	if (close(fs->jfd))
-		return -1;
+		ret = -1;
 	if (close(fs->jdirfd))
-		return -1;
+		ret = -1;
 	if (fs->name)
 		/* allocated by strdup() in jopen() */
 		free(fs->name);
 	munmap(fs->jmap, sizeof(unsigned int));
+
+	pthread_mutex_unlock(&(fs->lock));
 	pthread_mutex_destroy(&(fs->lock));
 
-	return 0;
+	return ret;
 }