Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An improper locking bug on the lock wiimote->rpt_mutex #42

Open
ycaibb opened this issue Aug 31, 2021 · 1 comment
Open

An improper locking bug on the lock wiimote->rpt_mutex #42

ycaibb opened this issue Aug 31, 2021 · 1 comment

Comments

@ycaibb
Copy link

ycaibb commented Aug 31, 2021

Hi, developers, thank you for your checking. It seems the lock wiimote->rpt_mutex is not released correctly when !rpt_mode & CWIID_RPT_IR==1 and exec_write_seq(wiimote, seq_len, ir_enable_seq)==1 in the function update_rpt_mode?

if (pthread_mutex_lock(&wiimote->rpt_mutex)) {

int update_rpt_mode(struct wiimote *wiimote, int8_t rpt_mode)
{
	...;

	/* rpt_mode = bitmask of requested report types */
	/* rpt_type = report id sent to the wiimote */
	if (pthread_mutex_lock(&wiimote->rpt_mutex)) {
		cwiid_err(wiimote, "Mutex lock error (rpt mutex)");
		return -1;  // <====================lack an unlock statement
	}

	...;
	...;
	if ((rpt_mode & CWIID_RPT_IR)) {
		if (exec_write_seq(wiimote, seq_len, ir_enable_seq)) {
			cwiid_err(wiimote, "IR enable error");
			return -1;
		}
	}
	
        ...;
	if (pthread_mutex_unlock(&wiimote->rpt_mutex)) {
		cwiid_err(wiimote, "Mutex unlock error (rpt mutex) - "
		          "deadlock warning");
		return -1;
	}

	return 0;
}

Best,

@ycaibb
Copy link
Author

ycaibb commented Sep 5, 2021

Also, the below codes could be improved to release the lock before program exit for better resource management

static CURL* get_connection(const char* path)
{
  pthread_mutex_lock(&pool_mut);
  CURL* curl = curl_pool_count ? curl_pool[--curl_pool_count] : curl_easy_init();
  if (!curl)
  {
    debugf(DBG_LEVEL_NORM, KRED"curl alloc failed");
    abort();
  }
  pthread_mutex_unlock(&pool_mut);
  return curl;
}

https://github.com/TurboGit/hubicfuse/blob/34a6c3e57467b5f7e9befe2171bf4292893c5a18/cloudfsapi.c#L102-L113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant