Skip to content

Commit

Permalink
8317919: pthread_attr_init handle return value and destroy pthread_at…
Browse files Browse the repository at this point in the history
…tr_t object

Reviewed-by: mdoerr, lucy
  • Loading branch information
MBaesken committed Oct 13, 2023
1 parent ff0b397 commit ec310fe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/hotspot/os/aix/os_aix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,8 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,

// Init thread attributes.
pthread_attr_t attr;
pthread_attr_init(&attr);
int rslt = pthread_attr_init(&attr);
guarantee(rslt == 0, "pthread_attr_init has to return 0");
guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");

// Make sure we run in 1:1 kernel-user-thread mode.
Expand Down Expand Up @@ -803,6 +804,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
stack_size / K);
thread->set_osthread(nullptr);
delete osthread;
pthread_attr_destroy(&attr);
return false;
}

Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,12 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,

// init thread attributes
pthread_attr_t attr;
pthread_attr_init(&attr);
int rslt = pthread_attr_init(&attr);
if (rslt != 0) {
thread->set_osthread(nullptr);
delete osthread;
return false;
}
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

// Calculate stack size if it's not specified by caller.
Expand Down Expand Up @@ -960,6 +965,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
stack_size / K);
thread->set_osthread(nullptr);
delete osthread;
pthread_attr_destroy(&attr);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ static int isInAquaSession() {
pthread_attr_t attr;
int rc;

pthread_attr_init(&attr);
int rslt = pthread_attr_init(&attr);
if (rslt != 0) return;
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
pthread_attr_destroy(&attr);
}

void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,10 @@ SplashCreateThread(Splash * splash) {
pthread_attr_t attr;
int rc;

pthread_attr_init(&attr);
int rslt = pthread_attr_init(&attr);
if (rslt != 0) return;
rc = pthread_create(&thr, &attr, SplashScreenThread, (void *) splash);
pthread_attr_destroy(&attr);
}

void
Expand Down

1 comment on commit ec310fe

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.