DBus booleans seem to stamp on more space than a C99 boolean
[dhcpcd-ui] / src / libdhcpcd / main.c
index 327c3dfb32549ea87b1919186a47f834297e85b1..7bffcbe1548ccd8de7c5e885b2751d3c3cef87ee 100644 (file)
@@ -144,10 +144,9 @@ dhcpcd_open(char **error)
        }
        if (bus == NULL)
                return NULL;
-       con = malloc(sizeof(*con));
+       con = calloc(1, sizeof(*con));
        if (con == NULL)
                goto bad;
-       memset(con, 0, sizeof(*con));
        con->bus = bus;
        if (!dbus_connection_set_watch_functions(bus,
                dhcpcd_add_watch, dhcpcd_delete_watch, NULL, con, NULL))
@@ -198,6 +197,7 @@ dhcpcd_close(DHCPCD_CONNECTION *con)
                                l->next = con->next;
                        dbus_connection_unref(con->bus);
                        dhcpcd_if_free(con->interfaces);
+                       dhcpcd_wi_history_clear(con);
                        free(con->status);
                        free(con->error);
                        free(con);
@@ -397,20 +397,18 @@ dhcpcd_if_new(DHCPCD_CONNECTION *con, DBusMessageIter *array, char **order)
        DHCPCD_IF *i;
        char *s;
        uint32_t u32;
-       bool b;
-       int errors;
+       int b, errors;
 
        if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY) {
                errno = EINVAL;
                return NULL;
        }
        dbus_message_iter_recurse(array, &dict);
-       i = malloc(sizeof(*i));
+       i = calloc(1, sizeof(*i));
        if (i == NULL) {
                dhcpcd_error_set(con, 0, errno);
                return NULL;
        }
-       memset(i, 0, sizeof(*i));
        errors = con->errors;
        for (;
             dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY;
@@ -435,6 +433,8 @@ dhcpcd_if_new(DHCPCD_CONNECTION *con, DBusMessageIter *array, char **order)
                                break;
                        strlcpy(i->reason, s, sizeof(i->reason));
                } else if (strcmp(s, "Wireless") == 0) {
+                       /* b is an int as DBus booleans want more space than
+                        * a C99 boolean */
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_BOOLEAN, &b))
                                break;
                        i->wireless = b;
@@ -445,7 +445,7 @@ dhcpcd_if_new(DHCPCD_CONNECTION *con, DBusMessageIter *array, char **order)
                } else if (strcmp(s, "IPAddress") == 0) {
                        if (!dhcpcd_iter_get(con, &var, DBUS_TYPE_UINT32, &u32))
                                break;
-                               i->ip.s_addr = u32;
+                       i->ip.s_addr = u32;
                } else if (strcmp(s, "SubnetCIDR") == 0)
                        dbus_message_iter_get_basic(&var, &i->cidr);
                else if (order != NULL && strcmp(s, "InterfaceOrder") == 0)