{"record":{"id":"0c6b761c86d9e2f2","repo":"openjdk/jdk","slug":"oom-error-in-native-tmp-buffer-allocation-0c6b76","errorCode":null,"errorMessage":"OOM error in native tmp buffer allocation","messagePattern":"OOM error in native tmp buffer allocation","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/java.instrument/unix/native/libinstrument/FileSystemSupport_md.c","lineNumber":46,"sourceCode":"#include <string.h>\n\n#include \"FileSystemSupport_md.h\"\n\n/*\n * Solaris/Linux implementation of the file system support functions.\n */\n\n#define slash           '/'\n\nchar* basePath(const char* path) {\n    const char* last = strrchr(path, slash);\n    if (last == NULL) {\n        return (char*)path;\n    } else {\n        int len = last - path;\n        char* str = (char*)malloc(len+1);\n        if (str == NULL) {\n            fprintf(stderr, \"OOM error in native tmp buffer allocation\");\n            return NULL;\n        }\n        if (len > 0) {\n            memcpy(str, path, len);\n        }\n        str[len] = '\\0';\n        return str;\n    }\n}\n\nint isAbsolute(const char* path) {\n    return (path[0] == slash) ? 1 : 0;\n}\n\n/* Ported from src/solaris/classes/java/io/UnixFileSystem.java */\n\n/* A normal Unix pathname contains no duplicate slashes and does not end\n   with a slash.  It may be the empty string. */","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.instrument/unix/native/libinstrument/FileSystemSupport_md.c#L28-L64","documentation":"This message is emitted by the native (JNI) side of the JVM's instrumentation agent library (libinstrument) when a malloc for a small temporary path buffer fails. basePath() allocates a copy of the directory portion of a path (everything before the last '/') while resolving the agent JAR's location during -javaagent startup. A failure here means the process is out of native heap memory at agent-load time, and the function returns NULL, aborting agent path resolution and typically failing Agent_OnLoad.","triggerScenarios":"Starting the JVM with -javaagent:somepath.jar (or attach-based agent load) on a machine where native memory is exhausted (ulimit -v, cgroup limits, overcommit settings, container memory cap). basePath() is called on the agent JAR path string; only the malloc failure branch prints this.","commonSituations":"Containers (Docker/Kubernetes) with tight memory limits; ulimit -v set too low; hosts with strict overcommit (vm.overcommit_memory=2); very large native allocations elsewhere before JVM startup; CI runners with constrained memory.","solutions":["Raise the container/cgroup memory limit or ulimit -v so the JVM plus native allocations fit","Check vm.overcommit_memory / overcommit settings on the host if malloc fails despite free RAM","Reduce native memory pressure at startup (fewer concurrently loaded agents/libs, smaller -XX:MaxMetaspaceSize if metaspace competes for the cap)","Reproduce with a minimal command line (java -javaagent:app.jar -version) to confirm memory, not the agent itself, is the cause"],"exampleFix":"# before\ndocker run -m 128m myapp java -javaagent:/opt/agent.jar -jar app.jar\n\n# after\ndocker run -m 1g myapp java -javaagent:/opt/agent.jar -jar app.jar","handlingStrategy":"validation","validationCode":"// Before launching, verify memory headroom exists for native allocations\n// POSIX: check address-space limit is not smothering small mallocs\nlong addressSpaceLimit = com.sun.management.OperatingSystemMXBean.class.isInstance(osMxBean) ? -1 : -1; // native limits not visible via Java; use shell checks instead:\n# ulimit -v  -> should be 'unlimited' or comfortably above JVM+native needs\n# free -m    -> verify available memory before 'java -javaagent:...' starts","typeGuard":null,"tryCatchPattern":"// Native fprintf+NULL is not catchable from Java; guard at launch time instead.\n// If agent load fails, the JVM exits with 'Error opening zip file or JAR manifest missing' style diagnostics —\n// treat any -javaagent startup failure as environmental and validate memory before retrying.","preventionTips":["Size container/cgroup memory limits to heap + metaspace + native headroom (rule of thumb: 25-50% above -Xmx)","Set ulimit -v to unlimited (or a generous value) for JVM processes in CI and systemd units","Smoke-test every agent deployment with 'java -javaagent:app.jar -version' in the target environment before shipping"],"tags":["native","oom","memory","javaagent","libinstrument","path-handling"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}