Skip to content

Commit 2867acd

Browse files
committed
8317919: pthread_attr_init handle return value and destroy pthread_attr_t object
Backport-of: ec310fe80971261ab7ee1141c64ffd600e7546c0
1 parent 3d71029 commit 2867acd

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/hotspot/os/aix/os_aix.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,8 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
750750

751751
// Init thread attributes.
752752
pthread_attr_t attr;
753-
pthread_attr_init(&attr);
753+
int rslt = pthread_attr_init(&attr);
754+
guarantee(rslt == 0, "pthread_attr_init has to return 0");
754755
guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
755756

756757
// Make sure we run in 1:1 kernel-user-thread mode.
@@ -782,6 +783,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
782783
stack_size / K);
783784
thread->set_osthread(nullptr);
784785
delete osthread;
786+
pthread_attr_destroy(&attr);
785787
return false;
786788
}
787789

src/hotspot/os/linux/os_linux.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,12 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
917917

918918
// init thread attributes
919919
pthread_attr_t attr;
920-
pthread_attr_init(&attr);
920+
int rslt = pthread_attr_init(&attr);
921+
if (rslt != 0) {
922+
thread->set_osthread(nullptr);
923+
delete osthread;
924+
return false;
925+
}
921926
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
922927

923928
// Calculate stack size if it's not specified by caller.
@@ -966,6 +971,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
966971
stack_size / K);
967972
thread->set_osthread(nullptr);
968973
delete osthread;
974+
pthread_attr_destroy(&attr);
969975
return false;
970976
}
971977

src/java.desktop/macosx/native/libsplashscreen/splashscreen_sys.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,10 @@ static int isInAquaSession() {
273273
pthread_attr_t attr;
274274
int rc;
275275

276-
pthread_attr_init(&attr);
276+
int rslt = pthread_attr_init(&attr);
277+
if (rslt != 0) return;
277278
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
279+
pthread_attr_destroy(&attr);
278280
}
279281

280282
void

src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,10 @@ SplashCreateThread(Splash * splash) {
773773
pthread_attr_t attr;
774774
int rc;
775775

776-
pthread_attr_init(&attr);
776+
int rslt = pthread_attr_init(&attr);
777+
if (rslt != 0) return;
777778
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
779+
pthread_attr_destroy(&attr);
778780
}
779781

780782
void

0 commit comments

Comments
 (0)