[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170921073420.dcoipli2sxy3bmnx@unicorn.suse.cz>
Date: Thu, 21 Sep 2017 09:34:20 +0200
From: Michal Kubecek <mkubecek@...e.cz>
To: Hangbin Liu <liuhangbin@...il.com>
Cc: Stephen Hemminger <stephen@...workplumber.org>,
netdev@...r.kernel.org, Phil Sutter <phil@....cc>
Subject: Re: [PATCHv3 iproute2 1/2] lib/libnetlink: re malloc buff if size is
not enough
On Thu, Sep 21, 2017 at 03:20:02PM +0800, Hangbin Liu wrote:
>
> Or maybe we can set buf_len very small first. Then it will force to realloc at
> the second time. And the code would like
>
> int buf_len = 16;
> bufp = realloc(buf, buf_len);
> /* check bufp and set msg */
>
> len = recvmsg(fd, msg, flag);
> /* check len */
>
> buf_len = len;
> bufp = realloc(buf, buf_len);
> /* check bufp and set msg */
>
> len = recvmsg(fd, msg, flag);
> /* check len */
>
> What do you think?
I will have to check but IIRC it might be possible to use zero length
for the peek to only check the length which could help you to avoid both
the reallocation and copying the same data from kernel to userspace
twice.
Michal Kubecek
Powered by blists - more mailing lists