{"record":{"id":"57c97e8857660969","repo":"apache/hadoop","slug":"getclasspath-failed-calloc-s","errorCode":null,"errorMessage":"getClassPath: failed calloc: %s\n","messagePattern":"getClassPath: failed calloc: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c","lineNumber":616,"sourceCode":"        if ((length == 0) && (strlen(classpath) != 0)) {\n            fprintf(stderr, \"Something went wrong with getting the wildcard \\\n              expansion length\\n\" );\n        }\n#endif\n\n        expandedClasspath = strdup(classpath);\n\n#ifdef _LIBHDFS_JNI_HELPER_DEBUGGING_ON_\n        printf(\"Expanded classpath=%s\\n\", expandedClasspath);\n#endif\n\n        return expandedClasspath;\n    }\n\n    // Allocte memory for expanded classpath string\n    expandedClasspath = calloc(length, sizeof(char));\n    if (expandedClasspath == NULL) {\n        fprintf(stderr, \"getClassPath: failed calloc: %s\\n\", strerror(errno));\n        return NULL;\n    }\n\n    // Actual expansion\n    retval = getClassPath_helper(classpath, expandedClasspath);\n    if (retval < 0) {\n        free(expandedClasspath);\n        return NULL;\n    }\n\n    // This should not happen, but dotting i's and crossing t's\n    if (retval != length) {\n        fprintf(stderr,\n          \"Expected classpath expansion length to be %zu but instead got %zu\\n\",\n          length, retval);\n        free(expandedClasspath);\n        return NULL;\n    }","sourceCodeStart":598,"sourceCodeEnd":634,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c#L598-L634","documentation":"After a sizing pass computes the expanded classpath length, getClassPath allocates the result buffer with calloc(length, 1). On failure it prints 'failed calloc: ...' with strerror(errno) and returns NULL, so the expanded classpath is never built and the JVM is not created.","triggerScenarios":"Very large wildcard-expanded classpaths (the buffer can be megabytes) with insufficient free memory; ulimit -v or cgroup caps hit during allocation.","commonSituations":"Big Hadoop installations expanded via wildcards; constrained containers; the same conditions that cause the earlier strdup failure.","solutions":["Pre-expand and shorten the CLASSPATH so the calloc is small or unnecessary","Raise memory limits before the first libhdfs call","Replace wildcard entries with explicit jar lists"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if (hdfsConnect(uri, user) == NULL && errno == EINTERNAL) {\n    /* check stderr for 'failed calloc': shrink/expand wildcard entries or raise limits */\n}","preventionTips":["Pre-expand wildcards so the expansion buffer stays small","Set memory limits with JVM bootstrap headroom in mind"],"tags":["hdfs","libhdfs","classpath","out-of-memory","calloc"],"backgroundTag":"out-of-memory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}