summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-06-18 05:33:27 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-06-30 14:36:28 -0700
commitb1a034b648bdf16b365dae75c3dad914994b7fe6 (patch)
tree9b9e69c0091f4051b0c9af12eea9ebc8d08b5787
parent86d2a44bf85e8b29546a56207b0b0ed39f18a3c0 (diff)
libglusterfs: Prevent gf_fd_put'ing of unallocated fd
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
-rw-r--r--libglusterfs/src/fd.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
index f67bdc82802..b28fb047e4a 100644
--- a/libglusterfs/src/fd.c
+++ b/libglusterfs/src/fd.c
@@ -343,11 +343,21 @@ gf_fd_put (fdtable_t *fdtable, int32_t fd)
pthread_mutex_lock (&fdtable->lock);
{
fde = &fdtable->fdentries[fd];
- fdptr = fde->fd;
+ /* If the entry is not allocated, put operation must return
+ * without doing anything.
+ * This has the potential of masking out any bugs in a user of
+ * fd that ends up calling gf_fd_put twice for the same fd or
+ * for an unallocated fd, but thats a price we have to pay for
+ * ensuring sanity of our fd-table.
+ */
+ if (fde->next_free != GF_FDENTRY_ALLOCATED)
+ goto unlock_out;
+ fdptr = fde->fd;
fde->fd = NULL;
fde->next_free = fdtable->first_free;
fdtable->first_free = fd;
}
+unlock_out:
pthread_mutex_unlock (&fdtable->lock);
if (fdptr) {