Skip to content

A couple of potential problems with CJamRecorder #1788

@cdmahoney

Description

@cdmahoney

I've recently been playing around with Jamulus code (implementing inter process communication through an mqtt broker) and have come across a couple of potential problems with the implementation of CJamRecorder (they are not bugs at the moment, but could become so in the future.)

  1. CJamRecorder constructor does not initialize member variable currentSession of type CJamSession*. The variable is initialized in CJamRecorder::Start and set to nullptr in CJamRecorder::OnEnd, but any comparison of the pointer with nullptr before a call to CJamRecorder::Start will return false (for example, if CJamRecorder::OnDisconnected is called before CJamRecorder::Start, which can't happen with the current Jamulus source code, but which could occur if the call to JamController.GetRecordingEnabled before emitting ClientDisconnected is removed from CServer::DecodeReceiveData, which is what my modified code does.)
  2. ChIdMutex will not be unlocked after a call to ChIdMutex.lock if the calling method returns prematurely - for example, a return statement or exception within the code block between the calles to ChIdMutex.lock and ChIdMutex.unlock. QMutexLocker can be used to gain a lock which will always be freed when the enclosing block goes out of scope. Currently CJamRecorder::OnDisconnected contains a nested return statement which will be called if currentSession == nullptr resolves to true, returning from the method without releasing the lock.

As stated above, while the code currently works fine, if at some point CServer::DecodeReceiveData is modified to not call JamController.GetRecordingEnabled, both of these cases will provoke errors - the first will provoke a segmentation fault when a user disconnects if recording is not enabled, and if the first case is fixed the second case will provoke an permanent lock on the mutex in the same situation.

I'd be happy to make pull requests with the changes in the code for jamrecorder.h and jamrecorder.cpp to fix the issues.

Apologies if this is not the correct way to submit this potential issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions