- clientCtx = calloc(1, sizeof(struct AFB_clientCtx)); // init NULL clientContext
- if (clientCtx != NULL) {
- clientCtx->contexts = calloc ((unsigned)sessions.apicount, sizeof (void*));
- if (clientCtx->contexts != NULL) {
- /* generate the uuid */
- if (uuid == NULL) {
- uuid_generate(newuuid);
- uuid_unparse_lower(newuuid, clientCtx->uuid);
- } else {
- strcpy(clientCtx->uuid, uuid);
- }
- strcpy(clientCtx->token, sessions.initok);
- clientCtx->expiration = now + sessions.timeout;
- clientCtx->refcount = 1;
- if (ctxStoreAdd (clientCtx))
- return clientCtx;
- free(clientCtx->contexts);
- }
- free(clientCtx);
+ clientCtx = calloc(1, sizeof(struct AFB_clientCtx) + ((unsigned)sessions.apicount * sizeof(*clientCtx->values)));
+ if (clientCtx == NULL) {
+ errno = ENOMEM;
+ goto error;