Tencent/matrix · critical

malloc failed

Error message

malloc failed

What it means

lemon.c's acttab_action() grows the aLookahead array with realloc (in chunks of 25 entries) as actions are recorded for parser table generation. When realloc fails to extend the array it prints "malloc failed" and exits with status 1. This is a fatal out-of-memory failure in the build-time parser generator used by matrix-sqlite-lint.

Solutions

  1. Re-run the build in an environment with more memory or a raised container memory limit
  2. Check and raise `ulimit -v` so realloc can grow the heap
  3. Lower native build parallelism (fewer -j jobs) to relieve memory pressure and retry
  4. Retry after transient memory pressure subsides; realloc failures are usually environment-related

Example fix

// before
export ULIMIT_V=$(ulimit -v)  # e.g. 262144 KB, too low
// after
ulimit -v unlimited && ./gradlew :matrix-sqlite-lint:build
Defensive patterns

Strategy: retry

Prevention

When it happens

Trigger: During ReportTable, calling acttab_action() repeatedly until nLookahead reaches nLookaheadAlloc and the realloc of aLookahead to the new size returns NULL.

Common situations: Building matrix-sqlite-lint under a memory-capped CI container or an OOM-stressed host; very low `ulimit -v` restricting heap growth; generating parser tables while many other compile jobs run in parallel.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/64bd0d41dc16feab. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c:456

acttab *acttab_alloc(void){
  acttab *p = malloc( sizeof(*p) );
  if( p==0 ){
    fprintf(stderr,"Unable to allocate memory for a new acttab.");
    exit(1);
  }
  memset(p, 0, sizeof(*p));
  return p;
}

/* Add a new action to the current transaction set
*/
void acttab_action(acttab *p, int lookahead, int action){
  if( p->nLookahead>=p->nLookaheadAlloc ){
    p->nLookaheadAlloc += 25;
    p->aLookahead = realloc( p->aLookahead,
                             sizeof(p->aLookahead[0])*p->nLookaheadAlloc );
    if( p->aLookahead==0 ){
      fprintf(stderr,"malloc failed\n");
      exit(1);
    }
  }
  if( p->nLookahead==0 ){
    p->mxLookahead = lookahead;
    p->mnLookahead = lookahead;
    p->mnAction = action;
  }else{
    if( p->mxLookahead<lookahead ) p->mxLookahead = lookahead;
    if( p->mnLookahead>lookahead ){
      p->mnLookahead = lookahead;
      p->mnAction = action;
    }
  }
  p->aLookahead[p->nLookahead].lookahead = lookahead;
  p->aLookahead[p->nLookahead].action = action;
  p->nLookahead++;
}

View on GitHub (pinned to 3b8293bd65)