diff --git a/ChangeLog b/ChangeLog index b3bfff79..2a00a888 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,7 +25,11 @@ Paul Davis Jackdmp changes log --------------------------- -2009-11-10 Stephane Letz +2009-11-12 Stephane Letz + + * Better memory allocation error checking on client (library) side. + +2009-11-11 Stephane Letz * Correct JackCoreAudio driver when empty strings are given as -C, -P or -d parameter. diff --git a/common/JackAPI.cpp b/common/JackAPI.cpp index 8ca99bd4..d22b1856 100644 --- a/common/JackAPI.cpp +++ b/common/JackAPI.cpp @@ -1943,5 +1943,7 @@ jack_get_version_string() EXPORT void jack_free(void* ptr) { - free(ptr); + if (ptr) { + free(ptr); + } } diff --git a/common/JackClient.cpp b/common/JackClient.cpp index 84049402..e6469267 100644 --- a/common/JackClient.cpp +++ b/common/JackClient.cpp @@ -988,14 +988,7 @@ char* JackClient::GetInternalClientName(int ref) char name_res[JACK_CLIENT_NAME_SIZE + 1]; int result = -1; fChannel->GetInternalClientName(GetClientControl()->fRefNum, ref, name_res, &result); - - if (result < 0) { - return NULL; - } else { - char* name = (char*)malloc(strlen(name_res)); - strcpy(name, name_res); - return name; - } + return (result < 0) ? NULL : strdup(name_res); } int JackClient::InternalClientHandle(const char* client_name, jack_status_t* status) diff --git a/common/JackGraphManager.cpp b/common/JackGraphManager.cpp index 434f5a59..d16becd6 100644 --- a/common/JackGraphManager.cpp +++ b/common/JackGraphManager.cpp @@ -702,6 +702,9 @@ const char** JackGraphManager::GetConnections(jack_port_id_t port_index) { const char** res = (const char**)malloc(sizeof(char*) * CONNECTION_NUM_FOR_PORT); UInt16 cur_index, next_index; + + if (!res) + return NULL; do { cur_index = GetCurrentIndex(); @@ -782,6 +785,9 @@ const char** JackGraphManager::GetPorts(const char* port_name_pattern, const cha { const char** res = (const char**)malloc(sizeof(char*) * PORT_NUM); UInt16 cur_index, next_index; + + if (!res) + return NULL; do { cur_index = GetCurrentIndex(); diff --git a/common/jack/jslist.h b/common/jack/jslist.h index 18773708..3ec0ce92 100644 --- a/common/jack/jslist.h +++ b/common/jack/jslist.h @@ -48,8 +48,10 @@ jack_slist_alloc (void) JSList *new_list; new_list = (JSList*)malloc(sizeof(JSList)); - new_list->data = NULL; - new_list->next = NULL; + if (new_list) { + new_list->data = NULL; + new_list->next = NULL; + } return new_list; } @@ -61,8 +63,10 @@ jack_slist_prepend (JSList* list, void* data) JSList *new_list; new_list = (JSList*)malloc(sizeof(JSList)); - new_list->data = data; - new_list->next = list; + if (new_list) { + new_list->data = data; + new_list->next = list; + } return new_list; }