Tencent/matrix · critical
Out of memory. Aborting...
Error message
Out of memory. Aborting...
What it means
memory_error() is lemon's single shared OOM handler: it prints 'Out of memory. Aborting...' to stderr and exits with status 1. It is invoked mostly via the MemoryCheck macro after allocation helpers like memory check macros in structdef, so any internal table/string allocation that fails routes here. It means the parser-generation step has exhausted process memory and cannot continue.
Solutions
- Increase available memory (ulimit, container limits, swap) and rerun.
- Inspect the grammar size / generated symbol counts; split an oversized grammar or remove generated duplication.
- Run with a memory profiler (valgrind massif) to see if a lemon bug leaks memory before the failure.
- Upgrade to a newer lemon.c that may have allocation-efficiency fixes.
- Pre-check input file size and reject absurdly large inputs before invoking lemon.
Defensive patterns
Strategy: retry
Validate before calling
# shell pre-check before invoking lemon
free_kb=$(awk '/MemAvailable/{print $2}' /proc/meminfo)
[ "$free_kb" -lt 65536 ] && { echo "insufficient memory for lemon"; exit 1; } Try / catch
retry with backoff around the lemon process, since OOM is often transient: for i in 1 2 3; do lemon grammar.y && break; sleep $((i*i)); done
Prevention
- Guarantee headroom in CI containers (raise memory cgroup limits)
- Check /proc/meminfo or cgroup memory.before invoking codegen
- Watch for grammar features that explode state/config counts
- Keep lemon.c updated for allocation efficiency fixes
When it happens
Trigger: Any MemoryCheck(...) or direct call to memory_error() after x = malloc(...) / realloc(...) returns NULL inside lemon (e.g. set/hashtable/string-pool growth) while parsing a grammar, usually driven by large or pathological .y inputs.
Common situations: Generating parsers from very large grammars; memory-limited CI containers; systems under memory pressure; accidentally passing a huge or binary file to lemon that blows up symbol tables.
Related errors
- Unable to allocate memory for a new configuration.
- 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/067b3e14c10b36c3.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c:1359
base = 0;
while( errmsg[base]!=0 ){
end = restart = findbreak(&errmsg[base],0,availablewidth);
restart += base;
while( errmsg[restart]==' ' ) restart++;
fprintf(stdout,"%s%.*s\n",prefix,end,&errmsg[base]);
base = restart;
}
}
/**************** From the file "main.c" ************************************/
/*
** Main program file for the LEMON parser generator.
*/
/* Report an out-of-memory condition and abort. This function
** is used mostly by the "MemoryCheck" macro in struct.h
*/
void memory_error(){
fprintf(stderr,"Out of memory. Aborting...\n");
exit(1);
}
static int nDefine = 0; /* Number of -D options on the command line */
static char **azDefine = 0; /* Name of the -D macros */
/* This routine is called with the argument to each -D command-line option.
** Add the macro defined to the azDefine array.
*/
static void handle_D_option(char *z){
char **paz;
nDefine++;
azDefine = realloc(azDefine, sizeof(azDefine[0])*nDefine);
if( azDefine==0 ){
fprintf(stderr,"out of memory\n");
exit(1);
}
paz = &azDefine[nDefine-1];View on GitHub (pinned to 3b8293bd65)