Skip to content
This repository was archived by the owner on Jan 11, 2026. It is now read-only.

Commit 613ccb3

Browse files
committed
pthread_mutex_init error checking
1 parent 649071f commit 613ccb3

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

ccminer.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,8 +3036,18 @@ int main(int argc, char *argv[])
30363036
/* init stratum data.. */
30373037
memset(&stratum.url, 0, sizeof(stratum));
30383038

3039-
pthread_mutex_init(&stratum.sock_lock, NULL);
3040-
pthread_mutex_init(&stratum.work_lock, NULL);
3039+
int err = pthread_mutex_init(&stratum.sock_lock, NULL);
3040+
if(err != 0)
3041+
{
3042+
applog(LOG_ERR, "pthread_mutex_init error %d", err);
3043+
proper_exit(EXIT_FAILURE);
3044+
}
3045+
err = pthread_mutex_init(&stratum.work_lock, NULL);
3046+
if(err != 0)
3047+
{
3048+
applog(LOG_ERR, "pthread_mutex_init error %d", err);
3049+
proper_exit(EXIT_FAILURE);
3050+
}
30413051

30423052
if(curl_global_init(CURL_GLOBAL_ALL))
30433053
{
@@ -3295,12 +3305,23 @@ int main(int argc, char *argv[])
32953305
return 1;
32963306
}
32973307
}
3308+
int pterr;
32983309
for(i = 0; i < opt_n_threads; i++)
32993310
{
33003311
thr = &thr_info[i];
33013312
thr->gpu.monitor.sampling_flag = false;
3302-
pthread_mutex_init(&thr->gpu.monitor.lock, NULL);
3303-
pthread_cond_init(&thr->gpu.monitor.sampling_signal, NULL);
3313+
pterr = pthread_mutex_init(&thr->gpu.monitor.lock, NULL);
3314+
if(pterr != 0)
3315+
{
3316+
applog(LOG_ERR, "pthread_mutex_init error %d", pterr);
3317+
proper_exit(EXIT_FAILURE);
3318+
}
3319+
pterr = pthread_cond_init(&thr->gpu.monitor.sampling_signal, NULL);
3320+
if(pterr != 0)
3321+
{
3322+
applog(LOG_ERR, "pthread_cond_init error %d", pterr);
3323+
proper_exit(EXIT_FAILURE);
3324+
}
33043325
}
33053326

33063327
#ifdef USE_WRAPNVML

util.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,18 +2044,26 @@ bool stratum_handle_method(struct stratum_ctx *sctx, const char *s)
20442044

20452045
struct thread_q *tq_new(void)
20462046
{
2047-
struct thread_q *tq;
2048-
2049-
tq = (struct thread_q *)calloc(1, sizeof(*tq));
2047+
struct thread_q *tq = (struct thread_q *)calloc(1, sizeof(struct thread_q));
20502048
if(tq == NULL)
20512049
{
20522050
applog(LOG_ERR, "Out of memory!");
20532051
proper_exit(EXIT_FAILURE);
20542052
}
20552053

20562054
INIT_LIST_HEAD(&tq->q);
2057-
pthread_mutex_init(&tq->mutex, NULL);
2058-
pthread_cond_init(&tq->cond, NULL);
2055+
int err = pthread_mutex_init(&tq->mutex, NULL);
2056+
if(err != 0)
2057+
{
2058+
applog(LOG_ERR, "pthread_mutex_init error %d", err);
2059+
proper_exit(EXIT_FAILURE);
2060+
}
2061+
err = pthread_cond_init(&tq->cond, NULL);
2062+
if(err != 0)
2063+
{
2064+
applog(LOG_ERR, "pthread_cond_init error %d", err);
2065+
proper_exit(EXIT_FAILURE);
2066+
}
20592067

20602068
return tq;
20612069
}

0 commit comments

Comments
 (0)