[sheepdog] [PATCH v1] sheep: replace valloc with xvalloc
Bingpeng Zhu
nkuzbp at foxmail.com
Thu Sep 11 05:02:57 CEST 2014
I see.
Thanks!
------------------ Original ------------------
From: "Hitoshi Mitake";<mitake.hitoshi at lab.ntt.co.jp>;
Date: Thu, Sep 11, 2014 10:28 AM
To: "Bingpeng Zhu"<nkuzbp at foxmail.com>;
Cc: "sheepdog"<sheepdog at lists.wpkg.org>; "Bingpeng Zhu"<bingpeng.zbp at alibaba-inc.com>;
Subject: Re: [sheepdog] [PATCH v1] sheep: replace valloc with xvalloc
At Wed, 10 Sep 2014 19:52:10 +0800,
Bingpeng Zhu wrote:
>
> xvalloc is the wrapper function of valloc in lib/util.
> We should use xvalloc instead of valloc in our code.
>
> Signed-off-by: Bingpeng Zhu <bingpeng.zbp at alibaba-inc.com>
> ---
> sheep/plain_store.c | 4 +---
> sheep/request.c | 6 +-----
> 2 files changed, 2 insertions(+), 8 deletions(-)
xvalloc() can call panic() when it fails to allocate memory so I think
the below changes are too agressive. e.g. sheep can panic() when it
receives GET_HASH request from dog. In most cases like this, returning
SD_RES_NO_MEM is suitable than calling panic().
Thanks,
Hitoshi
>
> diff --git a/sheep/plain_store.c b/sheep/plain_store.c
> index 876582c..7ab0699 100644
> --- a/sheep/plain_store.c
> +++ b/sheep/plain_store.c
> @@ -691,9 +691,7 @@ int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
> }
>
> length = get_store_objsize(oid);
> - buf = valloc(length);
> - if (buf == NULL)
> - return SD_RES_NO_MEM;
> + buf = xvalloc(length);
>
> iocb.epoch = epoch;
> iocb.buf = buf;
> diff --git a/sheep/request.c b/sheep/request.c
> index 8a2e7dc..bc10b90 100644
> --- a/sheep/request.c
> +++ b/sheep/request.c
> @@ -690,11 +690,7 @@ static struct request *alloc_request(struct client_info *ci, int data_length)
>
> if (data_length) {
> req->data_length = data_length;
> - req->data = valloc(data_length);
> - if (!req->data) {
> - free(req);
> - return NULL;
> - }
> + req->data = xvalloc(data_length);
> }
>
> req->ci = ci;
> --
> 1.7.1
>
>
> --
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> http://lists.wpkg.org/mailman/listinfo/sheepdog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wpkg.org/pipermail/sheepdog/attachments/20140911/7917b062/attachment-0004.html>
More information about the sheepdog
mailing list