mirror of
https://github.com/godotengine/godot.git
synced 2026-01-06 10:11:57 +03:00
Replace malloc's with Godot's memalloc macro
This commit is contained in:
@@ -506,7 +506,8 @@ Array AudioDriverCoreAudio::_get_device_list(bool capture) {
|
||||
|
||||
UInt32 size = 0;
|
||||
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, nullptr, &size);
|
||||
AudioDeviceID *audioDevices = (AudioDeviceID *)malloc(size);
|
||||
AudioDeviceID *audioDevices = (AudioDeviceID *)memalloc(size);
|
||||
ERR_FAIL_NULL_V_MSG(audioDevices, list, "Out of memory.");
|
||||
AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, nullptr, &size, audioDevices);
|
||||
|
||||
UInt32 deviceCount = size / sizeof(AudioDeviceID);
|
||||
@@ -515,14 +516,15 @@ Array AudioDriverCoreAudio::_get_device_list(bool capture) {
|
||||
prop.mSelector = kAudioDevicePropertyStreamConfiguration;
|
||||
|
||||
AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, nullptr, &size);
|
||||
AudioBufferList *bufferList = (AudioBufferList *)malloc(size);
|
||||
AudioBufferList *bufferList = (AudioBufferList *)memalloc(size);
|
||||
ERR_FAIL_NULL_V_MSG(bufferList, list, "Out of memory.");
|
||||
AudioObjectGetPropertyData(audioDevices[i], &prop, 0, nullptr, &size, bufferList);
|
||||
|
||||
UInt32 channelCount = 0;
|
||||
for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++)
|
||||
channelCount += bufferList->mBuffers[j].mNumberChannels;
|
||||
|
||||
free(bufferList);
|
||||
memfree(bufferList);
|
||||
|
||||
if (channelCount >= 1) {
|
||||
CFStringRef cfname;
|
||||
@@ -534,17 +536,18 @@ Array AudioDriverCoreAudio::_get_device_list(bool capture) {
|
||||
|
||||
CFIndex length = CFStringGetLength(cfname);
|
||||
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
|
||||
char *buffer = (char *)malloc(maxSize);
|
||||
char *buffer = (char *)memalloc(maxSize);
|
||||
ERR_FAIL_NULL_V_MSG(buffer, list, "Out of memory.");
|
||||
if (CFStringGetCString(cfname, buffer, maxSize, kCFStringEncodingUTF8)) {
|
||||
// Append the ID to the name in case we have devices with duplicate name
|
||||
list.push_back(String(buffer) + " (" + itos(audioDevices[i]) + ")");
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
memfree(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
free(audioDevices);
|
||||
memfree(audioDevices);
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -561,7 +564,8 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
||||
|
||||
UInt32 size = 0;
|
||||
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, nullptr, &size);
|
||||
AudioDeviceID *audioDevices = (AudioDeviceID *)malloc(size);
|
||||
AudioDeviceID *audioDevices = (AudioDeviceID *)memalloc(size);
|
||||
ERR_FAIL_NULL_MSG(audioDevices, "Out of memory.");
|
||||
AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, nullptr, &size, audioDevices);
|
||||
|
||||
UInt32 deviceCount = size / sizeof(AudioDeviceID);
|
||||
@@ -570,14 +574,15 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
||||
prop.mSelector = kAudioDevicePropertyStreamConfiguration;
|
||||
|
||||
AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, nullptr, &size);
|
||||
AudioBufferList *bufferList = (AudioBufferList *)malloc(size);
|
||||
AudioBufferList *bufferList = (AudioBufferList *)memalloc(size);
|
||||
ERR_FAIL_NULL_MSG(bufferList, "Out of memory.");
|
||||
AudioObjectGetPropertyData(audioDevices[i], &prop, 0, nullptr, &size, bufferList);
|
||||
|
||||
UInt32 channelCount = 0;
|
||||
for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++)
|
||||
channelCount += bufferList->mBuffers[j].mNumberChannels;
|
||||
|
||||
free(bufferList);
|
||||
memfree(bufferList);
|
||||
|
||||
if (channelCount >= 1) {
|
||||
CFStringRef cfname;
|
||||
@@ -589,7 +594,8 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
||||
|
||||
CFIndex length = CFStringGetLength(cfname);
|
||||
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
|
||||
char *buffer = (char *)malloc(maxSize);
|
||||
char *buffer = (char *)memalloc(maxSize);
|
||||
ERR_FAIL_NULL_MSG(buffer, "Out of memory.");
|
||||
if (CFStringGetCString(cfname, buffer, maxSize, kCFStringEncodingUTF8)) {
|
||||
String name = String(buffer) + " (" + itos(audioDevices[i]) + ")";
|
||||
if (name == device) {
|
||||
@@ -598,11 +604,11 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
||||
}
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
memfree(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
free(audioDevices);
|
||||
memfree(audioDevices);
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
|
||||
Reference in New Issue
Block a user