Tencent/matrix · critical
Unable to allocate memory for a new configuration.
Error message
Unable to allocate memory for a new configuration.
What it means
This fatal error is printed by the lemon parser generator when malloc() fails to allocate a block for three new LALR(1) configuration structs used to seed the internal free-list. The library cannot recover from losing its configuration pool, so it prints this message to stderr and calls exit(1). It indicates the host machine has exhausted memory available to the process.
Solutions
- Free up memory or raise the memory limit (ulimit -v / container memory cgroup / swap) and rerun lemon.
- Check the grammar for runaway growth (huge rule counts, accidental repetition) that inflates the configuration set.
- Move the build to a machine with more RAM or a 64-bit toolchain.
- If leaks elsewhere in lemon are implicated, patch lemon.c to use calloc/realloc more defensively or track peak usage.
- Rebuild with a malloc that aborts loudly or uses overcommit to distinguish genuine OOM from limits.
Example fix
// before
freelist = (struct config *)malloc( sizeof(struct config)*amt );
if( freelist==0 ){
fprintf(stderr,"Unable to allocate memory for a new configuration.");
exit(1);
}
// after
freelist = (struct config *)calloc( amt, sizeof(struct config) );
if( freelist==0 ){
fprintf(stderr,"Out of memory allocating %d configs.\n", amt);
exit(1);
} Defensive patterns
Strategy: try-catch
Validate before calling
// before running lemon, check available memory vs. a floor
long pages = sysconf(_SC_AVPHYS_PAGES), ps = sysconf(_SC_PAGESIZE);
if (pages * ps < 64UL*1024*1024) { fprintf(stderr,"not enough free memory to run lemon\n"); return 1; } Try / catch
// C has no try/catch; the library exits(1). Wrap the process call:
int rc = system("lemon grammar.y");
if (rc != 0) { fprintf(stderr,"lemon failed (possibly OOM); freeing resources and retrying once\n"); /* free memory, raise limits, retry */ } Prevention
- Set a generous ulimit -v or container memory limit before builds
- Monitor free memory in CI before code-generation steps
- Keep grammars modest in size and split oversized ones
- Run lemon in a 64-bit build to avoid address-space exhaustion
When it happens
Trigger: malloc(sizeof(struct config)*3) returns NULL at lemon.c:1088 when the config free-list is empty and a new config is requested via Configlist_add/Confignew, because system memory or the malloc arena is exhausted.
Common situations: Running lemon on grammar files so large that earlier allocations already consumed available memory; running inside a container, CI job, or ulimit-restricted shell with a tiny memory cgroup; 32-bit builds where the heap address space is exhausted; severe system-wide memory pressure from other processes.
Related errors
- Out of memory. Aborting...
- out of memory
- Unable to allocate memory for a new parser action.
- Unable to allocate memory for a new acttab.
- malloc failed
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/451911f9a9cb4247.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c:1088
** Routines to processing a configuration list and building a state
** in the LEMON parser generator.
*/
static struct config *freelist = 0; /* List of free configurations */
static struct config *current = 0; /* Top of list of configurations */
static struct config **currentend = 0; /* Last on list of configs */
static struct config *basis = 0; /* Top of list of basis configs */
static struct config **basisend = 0; /* End of list of basis configs */
/* Return a pointer to a new configuration */
PRIVATE struct config *newconfig(){
struct config *new;
if( freelist==0 ){
int i;
int amt = 3;
freelist = (struct config *)malloc( sizeof(struct config)*amt );
if( freelist==0 ){
fprintf(stderr,"Unable to allocate memory for a new configuration.");
exit(1);
}
for(i=0; i<amt-1; i++) freelist[i].next = &freelist[i+1];
freelist[amt-1].next = 0;
}
new = freelist;
freelist = freelist->next;
return new;
}
/* The configuration "old" is no longer used */
PRIVATE void deleteconfig(old)
struct config *old;
{
old->next = freelist;
freelist = old;
}
View on GitHub (pinned to 3b8293bd65)