On Tue, Jul 1, 2014 at 9:53 PM, Lennart Poettering <[email protected]> wrote: > On Tue, 01.07.14 11:58, Eugene Yakubovich ([email protected]) > wrote: > >> +int sd_dhcp_client_set_hostname(sd_dhcp_client *client, >> + const char *hostname) { >> + >> + assert_return(client, -EINVAL); >> + >> + if (streq_ptr(client->hostname, hostname)) >> + return 0; >> + >> + free(client->hostname); >> + >> + if (hostname) { >> + client->hostname = strdup(hostname); >> + if (!client->hostname) >> + return -ENOMEM; >> + } else >> + client->hostname = NULL; > > I'd always recommend allocating the new string first, and only then > freeing the old string. That way the function either fails with no > change to the object, or it succeeds, but never fails with a changed > object.
Already fixed this when pushing, so no need for resend. -t _______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
