Thread (7 messages) flat view 7 messages, 4 authors, 2017-09-28

Re: [PATCHv3 iproute2 1/2] lib/libnetlink: re malloc buff if size is not enough

From: Michal Kubecek <hidden>
Date: 2017-09-21 07:34:24

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help