Skip to content

Two potential errors due to the unreleased lock &init_mutex before program exit #1326

@jenny-cheung

Description

@jenny-cheung

Dear developers:
First, thank you for your checking! The lock pthread_mutex_lock(&init_mutex); is not released if the relevant branch conditions satisfy. The fix is to insert pthread_mutex_unlock(&init_mutex); before exit(1).

pthread_mutex_lock(&init_mutex);

static void *run_thread_poll_loop(void *data)
{
	...;
	
#ifdef USE_THREAD
	pthread_mutex_lock(&init_mutex);
#endif
	/* The first thread must set the number of threads left */
	if (!init_left)
		init_left = global.nbthread;
	init_left--;

	tv_init_thread_date();

	list_for_each_entry(ptaf, &per_thread_alloc_list, list) {
		if (!ptaf->fct()) {
			ha_alert("failed to allocate resources for thread %u.\n", tid);
			exit(1); // exit with unreleased lock
		}
	}

	list_for_each_entry(ptif, &per_thread_init_list, list) {
		if (!ptif->fct()) {
			ha_alert("failed to initialize thread %u.\n", tid);
			exit(1); // exit with unreleased lock
		}
	}

	if (init_left == 0)
		protocol_enable_all();

#ifdef USE_THREAD
	pthread_cond_broadcast(&init_cond);
	pthread_mutex_unlock(&init_mutex);

	...;
}

Best,

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: fixedThis issue is a now-fixed bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions