Browse Source

Memory allocation error checking in server for RPC.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3782 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/v1.9.4
sletz 16 years ago
parent
commit
13f0a7d5fe
8 changed files with 98 additions and 24 deletions
  1. +2
    -1
      ChangeLog
  2. +3
    -3
      common/JackEngine.cpp
  3. +2
    -2
      common/JackEngineControl.h
  4. +74
    -1
      common/JackLockedEngine.h
  5. +16
    -8
      common/JackServerAPI.cpp
  6. +1
    -1
      common/JackWeakAPI.cpp
  7. +0
    -4
      macosx/coreaudio/JackCoreAudioAdapter.cpp
  8. +0
    -4
      macosx/coreaudio/JackCoreAudioDriver.cpp

+ 2
- 1
ChangeLog View File

@@ -28,7 +28,8 @@ Paul Davis
2009-11-13 Stephane Letz <letz@grame.fr> 2009-11-13 Stephane Letz <letz@grame.fr>
* Better memory allocation error checking in ringbuffer.c, weak import improvements. * Better memory allocation error checking in ringbuffer.c, weak import improvements.
* Memory allocation error checking for jack_client_new and jack_client_open.
* Memory allocation error checking for jack_client_new and jack_client_open (server and client side).
* Memory allocation error checking in server for RPC.


2009-11-12 Stephane Letz <letz@grame.fr> 2009-11-12 Stephane Letz <letz@grame.fr>


+ 3
- 3
common/JackEngine.cpp View File

@@ -307,12 +307,12 @@ void JackEngine::NotifyFreewheel(bool onoff)
{ {
if (onoff) { if (onoff) {
// Save RT state // Save RT state
fEngineControl->fFWRealTime = fEngineControl->fRealTime;
fEngineControl->fSavedRealTime = fEngineControl->fRealTime;
fEngineControl->fRealTime = false; fEngineControl->fRealTime = false;
} else { } else {
// Restore RT state // Restore RT state
fEngineControl->fRealTime = fEngineControl->fFWRealTime;
fEngineControl->fFWRealTime = false;
fEngineControl->fRealTime = fEngineControl->fSavedRealTime;
fEngineControl->fSavedRealTime = false;
} }
NotifyClients((onoff ? kStartFreewheelCallback : kStopFreewheelCallback), true, "", 0, 0); NotifyClients((onoff ? kStartFreewheelCallback : kStopFreewheelCallback), true, "", 0, 0);
} }


+ 2
- 2
common/JackEngineControl.h View File

@@ -58,7 +58,7 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
float fXrunDelayedUsecs; float fXrunDelayedUsecs;
bool fTimeOut; bool fTimeOut;
bool fRealTime; bool fRealTime;
bool fFWRealTime; // RT state saved and restored during Freewheel mode
bool fSavedRealTime; // RT state saved and restored during Freewheel mode
int fServerPriority; int fServerPriority;
int fClientPriority; int fClientPriority;
int fMaxClientPriority; int fMaxClientPriority;
@@ -101,7 +101,7 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
fTimeOut = (timeout > 0); fTimeOut = (timeout > 0);
fTimeOutUsecs = timeout * 1000; fTimeOutUsecs = timeout * 1000;
fRealTime = rt; fRealTime = rt;
fFWRealTime = false;
fSavedRealTime = false;
fServerPriority = priority; fServerPriority = priority;
fClientPriority = (rt) ? priority - 5 : 0; fClientPriority = (rt) ? priority - 5 : 0;
fMaxClientPriority = (rt) ? priority - 1 : 0; fMaxClientPriority = (rt) ? priority - 1 : 0;


+ 74
- 1
common/JackLockedEngine.h View File

@@ -26,10 +26,29 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack namespace Jack
{ {


#define TRY_CALL \
try { \
#define CATCH_EXCEPTION_RETURN \
} catch(std::bad_alloc& e) { \
jack_error("Memory allocation error..."); \
return -1; \
} catch (...) { \
jack_error("Unknown error..."); \
return -1; \
} \

#define CATCH_ENGINE_EXCEPTION \
} catch(std::bad_alloc& e) { \
jack_error("Memory allocation error..."); \
} catch (...) { \
jack_error("Unknown error..."); \
} \

/*! /*!
\brief Locked Engine, access to methods is serialized using a mutex. \brief Locked Engine, access to methods is serialized using a mutex.
*/ */

class SERVER_EXPORT JackLockedEngine : public JackLockAble class SERVER_EXPORT JackLockedEngine : public JackLockAble
{ {
private: private:
@@ -47,108 +66,146 @@ class SERVER_EXPORT JackLockedEngine : public JackLockAble
int Open() int Open()
{ {
// No lock needed // No lock needed
TRY_CALL
return fEngine.Open(); return fEngine.Open();
CATCH_EXCEPTION_RETURN
} }
int Close() int Close()
{ {
// No lock needed // No lock needed
TRY_CALL
return fEngine.Close(); return fEngine.Close();
CATCH_EXCEPTION_RETURN
} }


// Client management // Client management
int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status) int ClientCheck(const char* name, char* name_res, int protocol, int options, int* status)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.ClientCheck(name, name_res, protocol, options, status); return fEngine.ClientCheck(name, name_res, protocol, options, status);
CATCH_EXCEPTION_RETURN
} }
int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager) int ClientExternalOpen(const char* name, int pid, int* ref, int* shared_engine, int* shared_client, int* shared_graph_manager)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager); return fEngine.ClientExternalOpen(name, pid, ref, shared_engine, shared_client, shared_graph_manager);
CATCH_EXCEPTION_RETURN
} }
int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait) int ClientInternalOpen(const char* name, int* ref, JackEngineControl** shared_engine, JackGraphManager** shared_manager, JackClientInterface* client, bool wait)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait); return fEngine.ClientInternalOpen(name, ref, shared_engine, shared_manager, client, wait);
CATCH_EXCEPTION_RETURN
} }


int ClientExternalClose(int refnum) int ClientExternalClose(int refnum)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.ClientExternalClose(refnum); return fEngine.ClientExternalClose(refnum);
CATCH_EXCEPTION_RETURN
} }
int ClientInternalClose(int refnum, bool wait) int ClientInternalClose(int refnum, bool wait)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.ClientInternalClose(refnum, wait); return fEngine.ClientInternalClose(refnum, wait);
CATCH_EXCEPTION_RETURN
} }


int ClientActivate(int refnum, bool is_real_time) int ClientActivate(int refnum, bool is_real_time)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.ClientActivate(refnum, is_real_time); return fEngine.ClientActivate(refnum, is_real_time);
CATCH_EXCEPTION_RETURN
} }
int ClientDeactivate(int refnum) int ClientDeactivate(int refnum)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.ClientDeactivate(refnum); return fEngine.ClientDeactivate(refnum);
CATCH_EXCEPTION_RETURN
} }


// Internal client management // Internal client management
int GetInternalClientName(int int_ref, char* name_res) int GetInternalClientName(int int_ref, char* name_res)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.GetInternalClientName(int_ref, name_res); return fEngine.GetInternalClientName(int_ref, name_res);
CATCH_EXCEPTION_RETURN
} }
int InternalClientHandle(const char* client_name, int* status, int* int_ref) int InternalClientHandle(const char* client_name, int* status, int* int_ref)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.InternalClientHandle(client_name, status, int_ref); return fEngine.InternalClientHandle(client_name, status, int_ref);
CATCH_EXCEPTION_RETURN
} }
int InternalClientUnload(int refnum, int* status) int InternalClientUnload(int refnum, int* status)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.InternalClientUnload(refnum, status); return fEngine.InternalClientUnload(refnum, status);
CATCH_EXCEPTION_RETURN
} }


// Port management // Port management
int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port) int PortRegister(int refnum, const char* name, const char *type, unsigned int flags, unsigned int buffer_size, jack_port_id_t* port)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.PortRegister(refnum, name, type, flags, buffer_size, port); return fEngine.PortRegister(refnum, name, type, flags, buffer_size, port);
CATCH_EXCEPTION_RETURN
} }
int PortUnRegister(int refnum, jack_port_id_t port) int PortUnRegister(int refnum, jack_port_id_t port)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.PortUnRegister(refnum, port); return fEngine.PortUnRegister(refnum, port);
CATCH_EXCEPTION_RETURN
} }


int PortConnect(int refnum, const char* src, const char* dst) int PortConnect(int refnum, const char* src, const char* dst)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.PortConnect(refnum, src, dst); return fEngine.PortConnect(refnum, src, dst);
CATCH_EXCEPTION_RETURN
} }
int PortDisconnect(int refnum, const char* src, const char* dst) int PortDisconnect(int refnum, const char* src, const char* dst)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.PortDisconnect(refnum, src, dst); return fEngine.PortDisconnect(refnum, src, dst);
CATCH_EXCEPTION_RETURN
} }


int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst) int PortConnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.PortConnect(refnum, src, dst); return fEngine.PortConnect(refnum, src, dst);
CATCH_EXCEPTION_RETURN
} }
int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst) int PortDisconnect(int refnum, jack_port_id_t src, jack_port_id_t dst)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.PortDisconnect(refnum, src, dst); return fEngine.PortDisconnect(refnum, src, dst);
CATCH_EXCEPTION_RETURN
} }
int PortRename(int refnum, jack_port_id_t port, const char* name) int PortRename(int refnum, jack_port_id_t port, const char* name)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.PortRename(refnum, port, name); return fEngine.PortRename(refnum, port, name);
CATCH_EXCEPTION_RETURN
} }


// Graph // Graph
@@ -167,46 +224,62 @@ class SERVER_EXPORT JackLockedEngine : public JackLockAble


void NotifyXRun(int refnum) void NotifyXRun(int refnum)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
fEngine.NotifyXRun(refnum); fEngine.NotifyXRun(refnum);
CATCH_ENGINE_EXCEPTION
} }
void NotifyGraphReorder() void NotifyGraphReorder()
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
fEngine.NotifyGraphReorder(); fEngine.NotifyGraphReorder();
CATCH_ENGINE_EXCEPTION
} }
void NotifyBufferSize(jack_nframes_t buffer_size) void NotifyBufferSize(jack_nframes_t buffer_size)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
fEngine.NotifyBufferSize(buffer_size); fEngine.NotifyBufferSize(buffer_size);
CATCH_ENGINE_EXCEPTION
} }
void NotifySampleRate(jack_nframes_t sample_rate) void NotifySampleRate(jack_nframes_t sample_rate)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
fEngine.NotifySampleRate(sample_rate); fEngine.NotifySampleRate(sample_rate);
CATCH_ENGINE_EXCEPTION
} }
void NotifyFreewheel(bool onoff) void NotifyFreewheel(bool onoff)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
fEngine.NotifyFreewheel(onoff); fEngine.NotifyFreewheel(onoff);
CATCH_ENGINE_EXCEPTION
} }
void NotifyFailure(int code, const char* reason) void NotifyFailure(int code, const char* reason)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
fEngine.NotifyFailure(code, reason); fEngine.NotifyFailure(code, reason);
CATCH_ENGINE_EXCEPTION
} }
int GetClientPID(const char* name) int GetClientPID(const char* name)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.GetClientPID(name); return fEngine.GetClientPID(name);
CATCH_EXCEPTION_RETURN
} }
int GetClientRefNum(const char* name) int GetClientRefNum(const char* name)
{ {
TRY_CALL
JackLock lock(this); JackLock lock(this);
return fEngine.GetClientRefNum(name); return fEngine.GetClientRefNum(name);
CATCH_EXCEPTION_RETURN
} }
}; };


+ 16
- 8
common/JackServerAPI.cpp View File

@@ -105,14 +105,22 @@ EXPORT jack_client_t* jack_client_open_aux(const char* client_name, jack_options


EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...) EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
{ {
assert(JackGlobals::fOpenMutex);
JackGlobals::fOpenMutex->Lock();
va_list ap;
va_start(ap, status);
jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
va_end(ap);
JackGlobals::fOpenMutex->Unlock();
return res;
try {
assert(JackGlobals::fOpenMutex);
JackGlobals::fOpenMutex->Lock();
va_list ap;
va_start(ap, status);
jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
va_end(ap);
JackGlobals::fOpenMutex->Unlock();
return res;
} catch(std::bad_alloc& e) {
jack_error("Memory allocation error...");
return NULL;
} catch (...) {
jack_error("Unknown error...");
return NULL;
}
} }


EXPORT int jack_client_close(jack_client_t* ext_client) EXPORT int jack_client_close(jack_client_t* ext_client)


+ 1
- 1
common/JackWeakAPI.cpp View File

@@ -75,7 +75,7 @@ void *load_jack_function(const char *fn_name)
static fn_name##_ptr_t fn = 0; \ static fn_name##_ptr_t fn = 0; \
if (fn == 0) { fn = (fn_name##_ptr_t)load_jack_function(#fn_name); } \ if (fn == 0) { fn = (fn_name##_ptr_t)load_jack_function(#fn_name); } \
if (fn) return (*fn)arguments; \ if (fn) return (*fn)arguments; \
else return (return_type)0; \
else return (return_type)-1; \
} }


#define DECL_VOID_FUNCTION(fn_name, arguments_types, arguments) \ #define DECL_VOID_FUNCTION(fn_name, arguments_types, arguments) \


+ 0
- 4
macosx/coreaudio/JackCoreAudioAdapter.cpp View File

@@ -721,10 +721,6 @@ int JackCoreAudioAdapter::SetupBuffers(int inchannels)


// Prepare buffers // Prepare buffers
fInputData = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer)); fInputData = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer));
if (fInputData == 0) {
jack_error("Cannot allocate memory for input buffers");
return -1;
}
fInputData->mNumberBuffers = inchannels; fInputData->mNumberBuffers = inchannels;
for (int i = 0; i < fCaptureChannels; i++) { for (int i = 0; i < fCaptureChannels; i++) {
fInputData->mBuffers[i].mNumberChannels = 1; fInputData->mBuffers[i].mNumberChannels = 1;


+ 0
- 4
macosx/coreaudio/JackCoreAudioDriver.cpp View File

@@ -1163,10 +1163,6 @@ int JackCoreAudioDriver::SetupBuffers(int inchannels)
{ {
// Prepare buffers // Prepare buffers
fJackInputData = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer)); fJackInputData = (AudioBufferList*)malloc(sizeof(UInt32) + inchannels * sizeof(AudioBuffer));
if (fJackInputData == 0) {
jack_error("Cannot allocate memory for input buffers");
return -1;
}
fJackInputData->mNumberBuffers = inchannels; fJackInputData->mNumberBuffers = inchannels;
for (int i = 0; i < fCaptureChannels; i++) { for (int i = 0; i < fCaptureChannels; i++) {
fJackInputData->mBuffers[i].mNumberChannels = 1; fJackInputData->mBuffers[i].mNumberChannels = 1;


Loading…
Cancel
Save