Tencent/matrix · critical
out of memory
Error message
out of memory
What it means
handle_D_option() processes -D command-line defines for lemon. It reallocs the global azDefine array to grow by one entry, and if realloc returns NULL it prints 'out of memory' and exits(1). This is a fatal allocation failure while registering a -D macro name.
Solutions
- Free memory / raise limits (ulimit -v, container memory) and rerun lemon.
- Reduce the number of -D defines passed to lemon.
- Verify the build script isn't expanding variables into thousands of duplicate -D flags.
- Replace the realloc pattern to use a temporary pointer and report the requested size for diagnosability.
- Run lemon under valgrind to rule out prior heap corruption causing realloc failure.
Example fix
// before
azDefine = realloc(azDefine, sizeof(azDefine[0])*nDefine);
if( azDefine==0 ){
fprintf(stderr,"out of memory\n");
exit(1);
}
// after
char **pazNew = realloc(azDefine, sizeof(azDefine[0])*nDefine);
if( pazNew==0 ){
fprintf(stderr,"out of memory growing azDefine to %d entries\n", nDefine);
exit(1);
}
azDefine = pazNew; Defensive patterns
Strategy: validation
Validate before calling
# validate memory headroom and the -D list size before invoking lemon
[ ${#DEFINES[@]} -lt 1000 ] || { echo "too many -D defines"; exit 1; }
free_kb=$(awk '/MemAvailable/{print $2}' /proc/meminfo); [ "$free_kb" -ge 65536 ] || exit 1 Try / catch
// library exits(1); guard at process level
if (system("lemon -DFOO grammar.y") != 0) { /* raise limits and retry */ } Prevention
- Avoid passing long lists of -D defines; consolidate them in the grammar
- Raise ulimit/container memory before builds
- Ensure the build script is not duplicating flags via unquoted expansion
When it happens
Trigger: realloc(azDefine, sizeof(char*)*nDefine) returns NULL at lemon.c:1374 when processing a -D option on the lemon command line, because the heap is exhausted (or in edge cases realloc fails on an oversized/zero-size request).
Common situations: Passing many -D flags on a constrained system; memory-capped CI containers; general system OOM at the moment lemon starts; broken builds invoking lemon with an enormous generated -D list.
Related errors
- Unable to allocate memory for a new configuration.
- Out of memory. Aborting...
- Exactly one filename argument is required.
- sdkVersion is absent in result.info.
- manufacturer is absent in result.info.
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/43e5bd514eea7703.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c:1374
** 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];
*paz = malloc( strlen(z)+1 );
if( *paz==0 ){
fprintf(stderr,"out of memory\n");
exit(1);
}
strcpy(*paz, z);
for(z=*paz; *z && *z!='='; z++){}
*z = 0;
}
/* The main program. Parse the command line and do it... */
int main(argc,argv)
int argc;
char **argv;View on GitHub (pinned to 3b8293bd65)