Tencent/matrix · critical

Can't allocate space for a filename.

Error message

Can't allocate space for a filename.

What it means

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.

Solutions

  1. Free memory or raise the environment's memory limits and re-run lemon
  2. Shorten the grammar file path/name (run from a shorter working directory)
  3. Ensure the binary is built for a 64-bit target if address-space limits are the cause
  4. Check dmesg / OOM-killer logs to rule out system memory pressure
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the environment has free memory before generation
free -m | awk '/Mem:/{if ($7 < 65536) { print "low memory"; exit 1 }}'

Prevention

When it happens

Trigger: malloc(strlen(filename)+strlen(suffix)+5) returns NULL while lemon is generating output files (.c, .h, .out) for a grammar.

Common situations: 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.

Related errors


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

Appendix: source

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

/*********************** From the file "report.c" **************************/
/*
** Procedures for generating reports and tables in the LEMON parser generator.
*/

/* Generate a filename with the given suffix.  Space to hold the
** name comes from malloc() and must be freed by the calling
** function.
*/
PRIVATE char *file_makename(lemp,suffix)
struct lemon *lemp;
char *suffix;
{
  char *name;
  char *cp;

  name = malloc( strlen(lemp->filename) + strlen(suffix) + 5 );
  if( name==0 ){
    fprintf(stderr,"Can't allocate space for a filename.\n");
    exit(1);
  }
  strcpy(name,lemp->filename);
  cp = strrchr(name,'.');
  if( cp ) *cp = 0;
  strcat(name,suffix);
  return name;
}

/* Open a file with a name based on the name of the input file,
** but with a different (specified) suffix, and return a pointer
** to the stream */
PRIVATE FILE *file_open(lemp,suffix,mode)
struct lemon *lemp;
char *suffix;
char *mode;
{
  FILE *fp;

View on GitHub (pinned to 3b8293bd65)