[Sheepdog] fix fd leak RE: [PATCH v2 3/7] sheep: object cache proper

Liu Yuan namei.unix at gmail.com
Tue Mar 13 10:34:46 CET 2012


On 03/13/2012 05:08 PM, huxinwei wrote:

> Preventing cache_object_fd leak while being called in object_is_cached.
> 
> On the other hand, I do this think this part of code is subject to refactoring.
> The usage of cache_object_fd is really subtle ;)
> 


Yea, I already met this problem and have fixed some fd leak right now
(will be updated at v3).

cache_object_fd will be removed, maybe will come up with better API that
would reduce the risk of fd leak.

Thanks,
Yuan

> FYI.
> 
> Signed-off-by: Xinwei Hu <huxinwei at huawei.com >
> 
> diff --git a/sheep/object_cache.c b/sheep/object_cache.c
> index 27a64a9..f75b7a1 100644
> --- a/sheep/object_cache.c
> +++ b/sheep/object_cache.c
> @@ -457,8 +457,10 @@ int object_is_cached(uint64_t oid)
>         cache->oid = oid;
>         if (object_cache_lookup(cache, idx) < 0)
>                 return 0;
> -       else
> +       else {
> +               close(cache_object_fd);
>                 return 1; /* found it */
> +       }
>  }
> 
>  int object_cache_init(const char *p)
> 
> 





More information about the sheepdog mailing list