sahaRatul / sela

SimplE Lossless Audio
https://seladoc.netlify.com/
MIT License
209 stars 23 forks source link

An improper locking bug(e.g., deadlock) on the lock &mutex #33

Open ryancaicse opened 3 years ago

ryancaicse commented 3 years ago

Hi, developers, thank you for your checking. It seems the lock mutex is not released correctly whennum_bytes>0 in the function ao_plugin_play? Should it be a bug or on purpose?

int ao_plugin_play(ao_device *device, const char *output_samples,
        uint_32 num_bytes)
{
  pthread_mutex_lock(&mutex);
   ...;
    if(num_bytes>0){
      long wait = internal->buffersize*1000/(device->output_channels*device->bytewidth*device->rate);
      pthread_mutex_unlock(&mutex);
      wait = (wait/8)*1000;
      if(wait<1)wait=1;
      if(wait>500000)wait=500000;
      usleep(wait);
      pthread_mutex_lock(&mutex);
    }else{
      pthread_mutex_unlock(&mutex);
      break;
    }
  }
  return 1;
}

https://github.com/sahaRatul/sela/blob/ca09cbd80bd6084bca08288d980c7f6928571bbb/external/libao/src/plugins/arts/ao_arts.c#L313-L324

Best,

ryancaicse commented 3 years ago

Hi, developers, any comments are highly appreciated! @sahaRatul