[systemd-devel] [systemd-commits] src/libsystemd-dhcp src/systemd
Lennart Poettering
lennart at poettering.net
Thu Jan 16 08:35:42 PST 2014
On Mon, 06.01.14 03:35, Tom Gundersen (tomegun at kemper.freedesktop.org) wrote:
> + lease->dns = new0(struct in_addr*, len / 4 + 1);
> + if (!lease->dns)
> + return -ENOMEM;
> +
> + for (i = 0; i < len / 4; i++) {
> + lease->dns[i] = new0(struct in_addr, 1);
> + memcpy(&lease->dns[i]->s_addr, option + 4 * i, 4);
> + }
> +
> + lease->dns[i + 1] = NULL;
Isn't this a bit overkill? Why not just use an array of "struct in_addr"
rather than an array of "struct in_addr*"? I mean, even if we'd ignore
the overhead of malloc() here, the code is a lot more complex, and on
64bit you use double the memory for storing the pointer to the address
than for the actual address stored... ;-)
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list