[systemd-devel] [PATCH 12/28] dhcp: Add DHCP discover sending

Lennart Poettering lennart at poettering.net
Wed Nov 13 16:17:55 PST 2013


On Wed, 13.11.13 23:22, Patrik Flykt (patrik.flykt at linux.intel.com) wrote:

> +static int client_send_discover(DHCPClient *client)
> +{
> +        int err = 0;
> +        DHCPPacket *discover;
> +        int optlen, len;
> +        uint8_t *opt;
> +
> +        optlen = DHCP_CLIENT_MIN_OPTIONS_SIZE;
> +        len = sizeof(DHCPPacket) + optlen;
> +
> +        discover = malloc0(len);
> +        if (!discover)
> +                return -ENOBUFS;

Please use -ENOMEM for OOM errors

> +        err = __dhcp_network_send_raw_packet(client->index, discover, len);
> +
> +error:
> +        free(discover);
> +
> +        return err;

_cleanup_free_ is your friend and the best thing since sliced bread. It
allows you to get rid of all gotos here!

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list