From 7f35e46e9d6110ca8a15048e48706f0ff8c48edc Mon Sep 17 00:00:00 2001 From: Pavel Tikhomirov Date: Thu, 16 Jan 2025 10:25:24 +0800 Subject: [PATCH] net/sysctl: put common multiplier outside the brackets Also add an explanation of the logic behind this calculation. Signed-off-by: Pavel Tikhomirov --- criu/net.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/criu/net.c b/criu/net.c index efd52db32..97c53f84f 100644 --- a/criu/net.c +++ b/criu/net.c @@ -2149,10 +2149,16 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds) list_for_each_entry(p, &ns->net.ids, node) i++; + /* + * Here we allocate one single big buffer for storing multiple arrays + * of protobuf entries and pointers to entries in it and we later use + * xptr_pull_s to claim a part of this buffer of proper size for each + * particular array. Next we read data from sysctl files to those + * arrays and then finally save them into images. + */ o_buf = buf = xmalloc(i * (sizeof(NetnsId *) + sizeof(NetnsId)) + - size4 * (sizeof(SysctlEntry *) + sizeof(SysctlEntry)) * 2 + - size6 * (sizeof(SysctlEntry *) + sizeof(SysctlEntry)) * 2 + - sizex * (sizeof(SysctlEntry *) + sizeof(SysctlEntry))); + (size4 * 2 + size6 * 2 + sizex) * + (sizeof(SysctlEntry *) + sizeof(SysctlEntry))); if (!buf) goto out;