<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 1, 2014 at 12:53 PM, Lennart Poettering <span dir="ltr"><<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Tue, 01.07.14 11:58, Eugene Yakubovich (<a href="mailto:eugene.yakubovich@coreos.com">eugene.yakubovich@coreos.com</a>) wrote:<br>

<br>
> +int sd_dhcp_client_set_hostname(sd_dhcp_client *client,<br>
> +                        const char *hostname) {<br>
> +<br>
> +        assert_return(client, -EINVAL);<br>
> +<br>
> +        if (streq_ptr(client->hostname, hostname))<br>
> +                return 0;<br>
> +<br>
> +        free(client->hostname);<br>
> +<br>
> +        if (hostname) {<br>
> +                client->hostname = strdup(hostname);<br>
> +                if (!client->hostname)<br>
> +                        return -ENOMEM;<br>
> +        } else<br>
> +                client->hostname = NULL;<br>
<br>
</div>I'd always recommend allocating the new string first, and only then<br>
freeing the old string. That way the function either fails with no<br>
change to the object, or it succeeds, but never fails with a changed<br>
object.<br></blockquote><div><br></div><div>Absolutely. I have no idea what I was thinking. </div></div></div></div>