Move creation of symlink after memory allocation for binding structure. Fix missing initialization of parent. Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx> --- src/gadget.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gadget.c b/src/gadget.c index 050bea5..cba309d 100644 --- a/src/gadget.c +++ b/src/gadget.c @@ -789,21 +789,22 @@ int gadget_add_config_function(struct config *c, char *name, struct function *f) sprintf(bpath, "%s/%s", c->path, name); sprintf(fpath, "%s/%s", f->path, f->name); - ret = symlink(fpath, bpath); - if (ret < 0) { - ERRORNO("%s -> %s\n", bpath, fpath); - return ret; - } - b = malloc(sizeof(struct binding)); if (!b) { ERRORNO("allocating binding\n"); return -1; } + ret = symlink(fpath, bpath); + if (ret < 0) { + ERRORNO("%s -> %s\n", bpath, fpath); + return ret; + } + strcpy(b->name, name); strcpy(b->path, bpath); b->target = f; + b->parent = c; /* Insert in string order */ if (TAILQ_EMPTY(&c->bindings) || -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html