{"record":{"id":"64bd0d41dc16feab","repo":"Tencent/matrix","slug":"malloc-failed","errorCode":null,"errorMessage":"malloc failed\n","messagePattern":"malloc failed\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c","lineNumber":456,"sourceCode":"acttab *acttab_alloc(void){\n  acttab *p = malloc( sizeof(*p) );\n  if( p==0 ){\n    fprintf(stderr,\"Unable to allocate memory for a new acttab.\");\n    exit(1);\n  }\n  memset(p, 0, sizeof(*p));\n  return p;\n}\n\n/* Add a new action to the current transaction set\n*/\nvoid acttab_action(acttab *p, int lookahead, int action){\n  if( p->nLookahead>=p->nLookaheadAlloc ){\n    p->nLookaheadAlloc += 25;\n    p->aLookahead = realloc( p->aLookahead,\n                             sizeof(p->aLookahead[0])*p->nLookaheadAlloc );\n    if( p->aLookahead==0 ){\n      fprintf(stderr,\"malloc failed\\n\");\n      exit(1);\n    }\n  }\n  if( p->nLookahead==0 ){\n    p->mxLookahead = lookahead;\n    p->mnLookahead = lookahead;\n    p->mnAction = action;\n  }else{\n    if( p->mxLookahead<lookahead ) p->mxLookahead = lookahead;\n    if( p->mnLookahead>lookahead ){\n      p->mnLookahead = lookahead;\n      p->mnAction = action;\n    }\n  }\n  p->aLookahead[p->nLookahead].lookahead = lookahead;\n  p->aLookahead[p->nLookahead].action = action;\n  p->nLookahead++;\n}","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c#L438-L474","documentation":"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.","triggerScenarios":"During ReportTable, calling acttab_action() repeatedly until nLookahead reaches nLookaheadAlloc and the realloc of aLookahead to the new size returns NULL.","commonSituations":"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.","solutions":["Re-run the build in an environment with more memory or a raised container memory limit","Check and raise `ulimit -v` so realloc can grow the heap","Lower native build parallelism (fewer -j jobs) to relieve memory pressure and retry","Retry after transient memory pressure subsides; realloc failures are usually environment-related"],"exampleFix":"// before\nexport ULIMIT_V=$(ulimit -v)  # e.g. 262144 KB, too low\n// after\nulimit -v unlimited && ./gradlew :matrix-sqlite-lint:build","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Raise container/ulimit memory limits for native builds","Retry transient build failures automatically once","Keep grammar growth in check; regenerate parser tables on machines with ample RAM"],"tags":["c","memory","parser-generator","realloc"],"backgroundTag":"out-of-memory","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}