service: use blob_memdup()
authorFelix Fietkau <nbd@openwrt.org>
Sun, 25 May 2014 18:55:30 +0000 (20:55 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 25 May 2014 18:55:30 +0000 (20:55 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
service/instance.c
service/service.c
service/trigger.c

index 1b28a7a..4a45759 100644 (file)
@@ -408,10 +408,9 @@ instance_config_parse(struct service_instance *in)
                in->respawn_retry = vals[2];
        }
        if (tb[INSTANCE_ATTR_TRIGGER]) {
                in->respawn_retry = vals[2];
        }
        if (tb[INSTANCE_ATTR_TRIGGER]) {
-               in->trigger = malloc(blob_pad_len(tb[INSTANCE_ATTR_TRIGGER]));
+               in->trigger = blob_memdup(tb[INSTANCE_ATTR_TRIGGER]);
                if (!in->trigger)
                        return -1;
                if (!in->trigger)
                        return -1;
-               memcpy(in->trigger, tb[INSTANCE_ATTR_TRIGGER], blob_pad_len(tb[INSTANCE_ATTR_TRIGGER]));
                trigger_add(in->trigger, in);
        }
 
                trigger_add(in->trigger, in);
        }
 
index 3fc8424..c566bc7 100644 (file)
@@ -117,10 +117,9 @@ service_update(struct service *s, struct blob_attr *config, struct blob_attr **t
        service_validate_del(s);
 
        if (tb[SERVICE_SET_TRIGGER] && blobmsg_data_len(tb[SERVICE_SET_TRIGGER])) {
        service_validate_del(s);
 
        if (tb[SERVICE_SET_TRIGGER] && blobmsg_data_len(tb[SERVICE_SET_TRIGGER])) {
-               s->trigger = malloc(blob_pad_len(tb[SERVICE_SET_TRIGGER]));
+               s->trigger = blob_memdup(tb[SERVICE_SET_TRIGGER]);
                if (!s->trigger)
                        return -1;
                if (!s->trigger)
                        return -1;
-               memcpy(s->trigger, tb[SERVICE_SET_TRIGGER], blob_pad_len(tb[SERVICE_SET_TRIGGER]));
                trigger_add(s->trigger, s);
        }
 
                trigger_add(s->trigger, s);
        }
 
index 41fb55d..b7bdbc5 100644 (file)
@@ -323,8 +323,7 @@ void trigger_event(char *type, struct blob_attr *data)
                        continue;
                if (!strcmp(t->type, type)) {
                        if (t->timeout) {
                        continue;
                if (!strcmp(t->type, type)) {
                        if (t->timeout) {
-                               t->data = malloc(blob_pad_len(data));
-                               memcpy(t->data, data, blob_pad_len(data));
+                               t->data = blob_memdup(data);
                                uloop_timeout_set(&t->delay, t->timeout);
                        } else {
                                json_script_run(&t->jctx, "foo", data);
                                uloop_timeout_set(&t->delay, t->timeout);
                        } else {
                                json_script_run(&t->jctx, "foo", data);