{"record":{"id":"95782f5aa1b9bdf6","repo":"python/cpython","slug":"could-not-allocate-ld-bytes","errorCode":null,"errorMessage":"could not allocate %ld bytes\n","messagePattern":"could not allocate %ld bytes\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Programs/_freeze_module.c","lineNumber":104,"sourceCode":"read_text(const char *inpath)\n{\n    FILE *infile = fopen(inpath, \"rb\");\n    if (infile == NULL) {\n        fprintf(stderr, \"cannot open '%s' for reading\\n\", inpath);\n        return NULL;\n    }\n\n    struct _Py_stat_struct stat;\n    if (_Py_fstat_noraise(fileno(infile), &stat)) {\n        fprintf(stderr, \"cannot fstat '%s'\\n\", inpath);\n        fclose(infile);\n        return NULL;\n    }\n    size_t text_size = (size_t)stat.st_size;\n\n    char *text = (char *) malloc(text_size + 1);\n    if (text == NULL) {\n        fprintf(stderr, \"could not allocate %ld bytes\\n\", (long) text_size);\n        fclose(infile);\n        return NULL;\n    }\n    size_t n = fread(text, 1, text_size, infile);\n    fclose(infile);\n\n    if (n < text_size) {\n        fprintf(stderr, \"read too short: got %ld instead of %ld bytes\\n\",\n                (long) n, (long) text_size);\n        free(text);\n        return NULL;\n    }\n\n    text[text_size] = '\\0';\n    return (const char *)text;\n}\n\nstatic PyObject *","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Programs/_freeze_module.c#L86-L122","documentation":"Build-time error from Programs/_freeze_module.c: malloc() for a buffer of st_size+1 bytes failed, so the module source cannot be read into memory for compilation. It means the process was out of memory (or hit an allocation limit) at freeze time.","triggerScenarios":"Freezing a path that is actually enormous (accidentally pointing at a huge file or device), or building in a memory-constrained container/ci runner where malloc of even modest sizes fails.","commonSituations":"Low-memory CI containers (cgroup limits) building CPython; swap-less small VMs; an outpath/inpath mix-up pointing at a multi-GB file; ulimit -v set restrictively.","solutions":["Free memory or raise limits: increase container memory, check `ulimit -v`, close other jobs before rebuilding","Verify the inpath is the intended .py file and not something huge: `ls -l <inpath>`","Reduce parallelism (`make -j1`) during the freeze stage to lower peak memory","Add swap on small VMs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# shell: sanity-check input size before freezing\n# size=$(stat -c %s \"$IN\" 2>/dev/null || stat -f %z \"$IN\")\n# [ \"$size\" -lt 10000000 ] || { echo \"$IN suspiciously large\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Give CI containers enough memory for the build stage","Check `ulimit -v` in build environments","Lower make -j parallelism on small machines"],"tags":["cpython","build","freeze-module","out-of-memory"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}