{"record":{"id":"16906b22230f6201","repo":"apache/hadoop","slug":"getclasspath-helper-failed-strdup-s","errorCode":null,"errorMessage":"getClassPath_helper: failed strdup: %s\n","messagePattern":"getClassPath_helper: failed strdup: (.+?)\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":501,"sourceCode":"\n/**\n * Helper to expand classpaths. Returns the total length of the expanded\n * classpath. If expandedClasspath is not NULL, then fills that with the\n * expanded classpath. It assumes that expandedClasspath is of correct size, eg\n * allocated after using this function with expandedClasspath=NULL to get the\n * right size.\n */\nstatic ssize_t getClassPath_helper(const char *classpath, char* expandedClasspath)\n{\n    ssize_t length;\n    ssize_t retval;\n    char* expandedCP_curr;\n    char* cp_token;\n    char* classpath_dup;\n\n    classpath_dup = strdup(classpath);\n    if (classpath_dup == NULL) {\n        fprintf(stderr, \"getClassPath_helper: failed strdup: %s\\n\",\n          strerror(errno));\n        return -1;\n    }\n\n    length = 0;\n\n    // expandedCP_curr is the current pointer\n    expandedCP_curr = expandedClasspath;\n\n    cp_token = strtok(classpath_dup, PATH_SEPARATOR_STR);\n    while (cp_token != NULL) {\n        size_t tokenlen;\n\n#ifdef _LIBHDFS_JNI_HELPER_DEBUGGING_ON_\n        printf(\"%s\\n\", cp_token);\n#endif\n\n        tokenlen = strlen(cp_token);","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c#L483-L519","documentation":"getClassPath_helper begins by duplicating the CLASSPATH value with strdup so it can tokenize it with strtok. If the duplication fails, 'failed strdup: ...' is printed with strerror(errno) and -1 is returned, aborting classpath preparation and therefore JVM creation on the first libhdfs call.","triggerScenarios":"Process heap exhausted at JVM-initialization time; an extremely large CLASSPATH string combined with tight memory limits.","commonSituations":"Machine-generated multi-megabyte CLASSPATH variables; memory-capped containers starting processes that use libhdfs.","solutions":["Raise memory limits or free memory before the first libhdfs call (JVM init is lazy)","Trim the CLASSPATH to only the required jars"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"/* fail fast when the environment is oversized or memory is scarce */\nconst char *cp = getenv(\"CLASSPATH\");\nif (cp && strlen(cp) > 1 * 1024 * 1024) { /* trim before JVM init */ }","typeGuard":null,"tryCatchPattern":"if (hdfsConnect(uri, user) == NULL && errno == EINTERNAL) {\n    /* check stderr for 'failed strdup': free memory or shorten CLASSPATH, then retry once */\n}","preventionTips":["Keep CLASSPATH minimal and versioned","Provision enough memory before JVM bootstrap, which happens lazily on first libhdfs call"],"tags":["hdfs","libhdfs","classpath","out-of-memory","strdup"],"backgroundTag":"out-of-memory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}