diff options
author | Shehjar Tikoo <shehjart@gluster.com> | 2009-06-18 05:33:27 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-06-18 13:08:04 -0700 |
commit | bb451c37bc05c8a33130e6b93020378d742f0ca2 (patch) | |
tree | 4de29e9fbd09302efa811457f4d9950e4604ee67 /libglusterfs/src/fd.c | |
parent | 617de1c718d4f082c8a8cf86c258284f5c918b2c (diff) |
libglusterfs: Prevent gf_fd_put'ing of unallocated fd
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfs/src/fd.c')
-rw-r--r-- | libglusterfs/src/fd.c | 12 |
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) { |