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

  1. Increase available memory (ulimit, container limits, swap) and rerun.
  2. Inspect the grammar size / generated symbol counts; split an oversized grammar or remove generated duplication.
  3. Run with a memory profiler (valgrind massif) to see if a lemon bug leaks memory before the failure.
  4. Upgrade to a newer lemon.c that may have allocation-efficiency fixes.
  5. 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

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


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)