From 9bf8c2e62321d440570353135a201e526438562f Mon Sep 17 00:00:00 2001 From: Volker Simonis Date: Thu, 7 Dec 2023 13:01:17 +0000 Subject: [PATCH] 8311645: Memory leak in jspawnhelper spawnChild after JDK-8307990 Backport-of: 401c3dea5d8823bc9c0f40506ddad46e983ebf68 --- src/java.base/unix/native/libjava/ProcessImpl_md.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/java.base/unix/native/libjava/ProcessImpl_md.c b/src/java.base/unix/native/libjava/ProcessImpl_md.c index f8b3f122254..bb340a8f120 100644 --- a/src/java.base/unix/native/libjava/ProcessImpl_md.c +++ b/src/java.base/unix/native/libjava/ProcessImpl_md.c @@ -565,6 +565,7 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath) /* write the two structs and the data buffer */ if (writeFully(c->childenv[1], (char *)&magic, sizeof(magic)) != sizeof(magic)) { // magic number first + free(buf); return -1; } #ifdef DEBUG @@ -573,6 +574,7 @@ spawnChild(JNIEnv *env, jobject process, ChildStuff *c, const char *helperpath) if (writeFully(c->childenv[1], (char *)c, sizeof(*c)) != sizeof(*c) || writeFully(c->childenv[1], (char *)&sp, sizeof(sp)) != sizeof(sp) || writeFully(c->childenv[1], buf, bufsize) != bufsize) { + free(buf); return -1; } /* We're done. Let jspwanhelper know he can't expect any more data from us. */