[systemd-devel] [systemd-commits] src/libsystemd-dhcp src/systemd

Tom Gundersen teg at jklm.no
Thu Jan 16 11:13:02 PST 2014


On Thu, Jan 16, 2014 at 5:35 PM, Lennart Poettering
<lennart at poettering.net> wrote:
> 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... ;-)

Fair enough :-) Fixed locally, will push soon.

Cheers,

Tom


More information about the systemd-devel mailing list