mdbx: avoid on-stack allocation/chkstk inside mdbx_env_walk().

5 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43

Change-Id: Iadb833ff38dbd0922eda69238b365f5906b9109f
This commit is contained in:
Leonid Yuriev 2018-10-13 12:47:12 +03:00
parent 180c605cac
commit aa64597e8b

View File

@ -12793,9 +12793,20 @@ static int __cold mdbx_env_walk(mdbx_walk_ctx_t *ctx, const char *dbi,
MDBX_db db;
memcpy(&db, NODEDATA(node), sizeof(db));
char *name = memcpy(alloca(namelen + 1), NODEKEY(node), namelen);
name[namelen] = 0;
rc = mdbx_env_walk(ctx, name, db.md_root, deep + 1);
char namebuf_onstask[142];
char *const name = (namelen < sizeof(namebuf_onstask))
? namebuf_onstask
: mdbx_malloc(namelen + 1);
if (name) {
memcpy(name, NODEKEY(node), namelen);
name[namelen] = 0;
rc = mdbx_env_walk(ctx, name, db.md_root, deep + 1);
if (name != namebuf_onstask)
mdbx_free(name);
} else {
rc = MDBX_ENOMEM;
}
} break;
case F_SUBDATA | F_DUPDATA /* dupsorted sub-tree */: {