afb-export: Fix event handler of API 53/15653/1
authorJosé Bollo <jose.bollo@iot.bzh>
Tue, 24 Jul 2018 13:27:13 +0000 (15:27 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Tue, 24 Jul 2018 14:23:56 +0000 (16:23 +0200)
Change-Id: Ibadaf6f41e39cce398d33a2a2a73751d68dad34d
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/afb-export.c

index 799ad73..b40dd07 100644 (file)
@@ -1149,7 +1149,7 @@ int afb_export_event_handler_add(
        }
 
        /* create the event */
-       handler = malloc(strlen(pattern) + strlen(pattern));
+       handler = malloc(strlen(pattern) + sizeof * handler);
        if (!handler) {
                ERROR("[API %s] can't allocate event handler %s", export->api.apiname, pattern);
                errno = ENOMEM;
@@ -1161,7 +1161,7 @@ int afb_export_event_handler_add(
        handler->callback = callback;
        handler->closure = closure;
        strcpy(handler->pattern, pattern);
-       export->event_handlers = handler;
+       *previous = handler;
 
        return 0;
 }