Skip to content

Potential error(e.g., deadlock) due to the unreleased lock &mutex , similar to #379 but in different functions #382

@true-ryan

Description

@true-ryan

Hi, developers:
If the pthread_create return 0,i.e., fails to create the thread, the function returns immediately with the lock mutex unreleased. It is in the test folder but still worth fixing for higher quality. Thank you for your checking.

The fix is to insert pthread_mutex_unlock(&mutex); before returning.

pthread_mutex_lock(&mutex);

ret = pthread_create(&recv_thread, NULL, recv_fn, &rd);

return 1;

static int test(int buf_select, int no_buf_add, int iov_count)
{
	...;
	pthread_mutex_lock(&mutex);

	rd.mutex = &mutex;
	rd.buf_select = buf_select;
	rd.no_buf_add = no_buf_add;
	rd.iov_count = iov_count;
	ret = pthread_create(&recv_thread, NULL, recv_fn, &rd);
	if (ret) {
		fprintf(stderr, "Thread create failed\n"); //pthread_mutex_unlock(&mutex);
		return 1;
	}

	...;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions