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 1b28a7a2407eaa38529affa277371a170b9bf27c..4a457593b22019144b585a96ee467699401de9e4 100644 (file)
@@ -408,10 +408,9 @@ instance_config_parse(struct service_instance *in)
                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;
-               memcpy(in->trigger, tb[INSTANCE_ATTR_TRIGGER], blob_pad_len(tb[INSTANCE_ATTR_TRIGGER]));
                trigger_add(in->trigger, in);
        }
 
index 3fc84245280cf158f9773416d8d3828dfa538c85..c566bc70bf2d9a6a2969cc62bdcd32ad3850cc80 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])) {
-               s->trigger = malloc(blob_pad_len(tb[SERVICE_SET_TRIGGER]));
+               s->trigger = blob_memdup(tb[SERVICE_SET_TRIGGER]);
                if (!s->trigger)
                        return -1;
-               memcpy(s->trigger, tb[SERVICE_SET_TRIGGER], blob_pad_len(tb[SERVICE_SET_TRIGGER]));
                trigger_add(s->trigger, s);
        }
 
index 41fb55dc4c5288f65faf082c4075c6cd72c1f380..b7bdbc5beb86c18205bb3bc3eb0d36f0c4f503b4 100644 (file)
@@ -323,8 +323,7 @@ void trigger_event(char *type, struct blob_attr *data)
                        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);