{"record":{"id":"dd4db8b501dea5aa","repo":"Tencent/matrix","slug":"can-t-allocate-space-for-a-filename","errorCode":null,"errorMessage":"Can't allocate space for a filename.\n","messagePattern":"Can't allocate space for a filename\\.\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c","lineNumber":2663,"sourceCode":"/*********************** From the file \"report.c\" **************************/\n/*\n** Procedures for generating reports and tables in the LEMON parser generator.\n*/\n\n/* Generate a filename with the given suffix.  Space to hold the\n** name comes from malloc() and must be freed by the calling\n** function.\n*/\nPRIVATE char *file_makename(lemp,suffix)\nstruct lemon *lemp;\nchar *suffix;\n{\n  char *name;\n  char *cp;\n\n  name = malloc( strlen(lemp->filename) + strlen(suffix) + 5 );\n  if( name==0 ){\n    fprintf(stderr,\"Can't allocate space for a filename.\\n\");\n    exit(1);\n  }\n  strcpy(name,lemp->filename);\n  cp = strrchr(name,'.');\n  if( cp ) *cp = 0;\n  strcat(name,suffix);\n  return name;\n}\n\n/* Open a file with a name based on the name of the input file,\n** but with a different (specified) suffix, and return a pointer\n** to the stream */\nPRIVATE FILE *file_open(lemp,suffix,mode)\nstruct lemon *lemp;\nchar *suffix;\nchar *mode;\n{\n  FILE *fp;","sourceCodeStart":2645,"sourceCodeEnd":2681,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c#L2645-L2681","documentation":"Lemon's file_makename() mallocs a buffer to build an output filename from the input grammar filename plus a suffix. If malloc returns NULL, it prints 'Can't allocate space for a filename.' and exits 1.","triggerScenarios":"malloc(strlen(filename)+strlen(suffix)+5) returns NULL while lemon is generating output files (.c, .h, .out) for a grammar.","commonSituations":"Severe memory exhaustion/fragmentation; an absurdly long input filename pushing the allocation size into failure territory on constrained systems; running in a container whose memory limit has already been exhausted by earlier allocations.","solutions":["Free memory or raise the environment's memory limits and re-run lemon","Shorten the grammar file path/name (run from a shorter working directory)","Ensure the binary is built for a 64-bit target if address-space limits are the cause","Check dmesg / OOM-killer logs to rule out system memory pressure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure the environment has free memory before generation\nfree -m | awk '/Mem:/{if ($7 < 65536) { print \"low memory\"; exit 1 }}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep grammar file paths reasonably short","Avoid running lemon on already memory-saturated machines","Prefer 64-bit lemon builds","Investigate any pattern where lemon exits with allocation failures"],"tags":["memory","lemon","out-of-memory","filename"],"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"}