procd: Remove unnecessary memset calls.
authorRosen Penev <rosenp@gmail.com>
Tue, 7 Nov 2017 20:05:12 +0000 (12:05 -0800)
committerFelix Fietkau <nbd@nbd.name>
Mon, 13 Nov 2017 08:41:35 +0000 (09:41 +0100)
Changes allocation to calloc and {} as needed.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
inittab.c
plug/hotplug.c

index 21172f7..c27c324 100644 (file)
--- a/inittab.c
+++ b/inittab.c
@@ -284,8 +284,7 @@ void procd_inittab(void)
 
        regcomp(&pat_inittab, "([a-zA-Z0-9]*):([a-zA-Z0-9]*):([a-zA-Z0-9]*):(.*)", REG_EXTENDED);
        line = malloc(LINE_LEN);
-       a = malloc(sizeof(struct init_action));
-       memset(a, 0, sizeof(struct init_action));
+       a = calloc(1, sizeof(struct init_action));
 
        while (fgets(line, LINE_LEN, fp)) {
                char *tags[TAG_PROCESS + 1];
@@ -322,8 +321,7 @@ void procd_inittab(void)
                if (add_action(a, tags[TAG_ACTION]))
                        continue;
                line = malloc(LINE_LEN);
-               a = malloc(sizeof(struct init_action));
-               memset(a, 0, sizeof(struct init_action));
+               a = calloc(1, sizeof(struct init_action));
        }
 
        fclose(fp);
index ffedba2..9fc1938 100644 (file)
@@ -434,12 +434,10 @@ static void handle_button_complete(struct blob_attr *msg, struct blob_attr *data
        if (!name)
                return;
 
-       b = malloc(sizeof(*b));
+       b = calloc(1, sizeof(*b));
        if (!b)
                return;
 
-       memset(b, 0, sizeof(*b));
-
        b->data = malloc(blob_pad_len(data));
        b->name = strdup(name);
        b->seen = timeout;
@@ -584,11 +582,10 @@ void hotplug_last_event(uloop_timeout_handler handler)
 
 void hotplug(char *rules)
 {
-       struct sockaddr_nl nls;
+       struct sockaddr_nl nls = {};
        int nlbufsize = 512 * 1024;
 
        rule_file = strdup(rules);
-       memset(&nls,0,sizeof(struct sockaddr_nl));
        nls.nl_family = AF_NETLINK;
        nls.nl_pid = getpid();
        nls.nl_groups = -1;