Replace malloc's with Godot's memalloc macro
(cherry picked from commit 838e7d0a8d
)
This commit is contained in:
parent
7ca7acce7b
commit
a586f9daae
6 changed files with 37 additions and 25 deletions
|
@ -514,7 +514,8 @@ Array AudioDriverCoreAudio::_get_device_list(bool capture) {
|
||||||
|
|
||||||
UInt32 size = 0;
|
UInt32 size = 0;
|
||||||
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &size);
|
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &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, NULL, &size, audioDevices);
|
AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &size, audioDevices);
|
||||||
|
|
||||||
UInt32 deviceCount = size / sizeof(AudioDeviceID);
|
UInt32 deviceCount = size / sizeof(AudioDeviceID);
|
||||||
|
@ -523,14 +524,15 @@ Array AudioDriverCoreAudio::_get_device_list(bool capture) {
|
||||||
prop.mSelector = kAudioDevicePropertyStreamConfiguration;
|
prop.mSelector = kAudioDevicePropertyStreamConfiguration;
|
||||||
|
|
||||||
AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, NULL, &size);
|
AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, NULL, &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, NULL, &size, bufferList);
|
AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, bufferList);
|
||||||
|
|
||||||
UInt32 channelCount = 0;
|
UInt32 channelCount = 0;
|
||||||
for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++)
|
for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++)
|
||||||
channelCount += bufferList->mBuffers[j].mNumberChannels;
|
channelCount += bufferList->mBuffers[j].mNumberChannels;
|
||||||
|
|
||||||
free(bufferList);
|
memfree(bufferList);
|
||||||
|
|
||||||
if (channelCount >= 1) {
|
if (channelCount >= 1) {
|
||||||
CFStringRef cfname;
|
CFStringRef cfname;
|
||||||
|
@ -542,17 +544,18 @@ Array AudioDriverCoreAudio::_get_device_list(bool capture) {
|
||||||
|
|
||||||
CFIndex length = CFStringGetLength(cfname);
|
CFIndex length = CFStringGetLength(cfname);
|
||||||
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
|
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)) {
|
if (CFStringGetCString(cfname, buffer, maxSize, kCFStringEncodingUTF8)) {
|
||||||
// Append the ID to the name in case we have devices with duplicate name
|
// Append the ID to the name in case we have devices with duplicate name
|
||||||
list.push_back(String(buffer) + " (" + itos(audioDevices[i]) + ")");
|
list.push_back(String(buffer) + " (" + itos(audioDevices[i]) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
memfree(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(audioDevices);
|
memfree(audioDevices);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -570,7 +573,8 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
||||||
|
|
||||||
UInt32 size = 0;
|
UInt32 size = 0;
|
||||||
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &size);
|
AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &prop, 0, NULL, &size);
|
||||||
AudioDeviceID *audioDevices = (AudioDeviceID *)malloc(size);
|
AudioDeviceID *audioDevices = (AudioDeviceID *)memalloc(size);
|
||||||
|
ERR_FAIL_NULL_MSG(audioDevices, "Out of memory.");
|
||||||
AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &size, audioDevices);
|
AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &size, audioDevices);
|
||||||
|
|
||||||
UInt32 deviceCount = size / sizeof(AudioDeviceID);
|
UInt32 deviceCount = size / sizeof(AudioDeviceID);
|
||||||
|
@ -579,14 +583,15 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
||||||
prop.mSelector = kAudioDevicePropertyStreamConfiguration;
|
prop.mSelector = kAudioDevicePropertyStreamConfiguration;
|
||||||
|
|
||||||
AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, NULL, &size);
|
AudioObjectGetPropertyDataSize(audioDevices[i], &prop, 0, NULL, &size);
|
||||||
AudioBufferList *bufferList = (AudioBufferList *)malloc(size);
|
AudioBufferList *bufferList = (AudioBufferList *)memalloc(size);
|
||||||
|
ERR_FAIL_NULL_MSG(bufferList, "Out of memory.");
|
||||||
AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, bufferList);
|
AudioObjectGetPropertyData(audioDevices[i], &prop, 0, NULL, &size, bufferList);
|
||||||
|
|
||||||
UInt32 channelCount = 0;
|
UInt32 channelCount = 0;
|
||||||
for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++)
|
for (UInt32 j = 0; j < bufferList->mNumberBuffers; j++)
|
||||||
channelCount += bufferList->mBuffers[j].mNumberChannels;
|
channelCount += bufferList->mBuffers[j].mNumberChannels;
|
||||||
|
|
||||||
free(bufferList);
|
memfree(bufferList);
|
||||||
|
|
||||||
if (channelCount >= 1) {
|
if (channelCount >= 1) {
|
||||||
CFStringRef cfname;
|
CFStringRef cfname;
|
||||||
|
@ -598,7 +603,8 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
||||||
|
|
||||||
CFIndex length = CFStringGetLength(cfname);
|
CFIndex length = CFStringGetLength(cfname);
|
||||||
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
|
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)) {
|
if (CFStringGetCString(cfname, buffer, maxSize, kCFStringEncodingUTF8)) {
|
||||||
String name = String(buffer) + " (" + itos(audioDevices[i]) + ")";
|
String name = String(buffer) + " (" + itos(audioDevices[i]) + ")";
|
||||||
if (name == device) {
|
if (name == device) {
|
||||||
|
@ -607,11 +613,11 @@ void AudioDriverCoreAudio::_set_device(const String &device, bool capture) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buffer);
|
memfree(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(audioDevices);
|
memfree(audioDevices);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|
|
@ -416,8 +416,7 @@ GD_PINVOKE_EXPORT int32_t monodroid_get_system_property(const char *p_name, char
|
||||||
if (r_value) {
|
if (r_value) {
|
||||||
if (len >= 0) {
|
if (len >= 0) {
|
||||||
*r_value = (char *)malloc(len + 1);
|
*r_value = (char *)malloc(len + 1);
|
||||||
if (!*r_value)
|
ERR_FAIL_NULL_V_MSG(*r_value, -1, "Out of memory.");
|
||||||
return -1;
|
|
||||||
memcpy(*r_value, prop_value_str, len);
|
memcpy(*r_value, prop_value_str, len);
|
||||||
(*r_value)[len] = '\0';
|
(*r_value)[len] = '\0';
|
||||||
} else {
|
} else {
|
||||||
|
@ -638,6 +637,7 @@ GD_PINVOKE_EXPORT int32_t _monodroid_get_dns_servers(void **r_dns_servers_array)
|
||||||
if (dns_servers_count > 0) {
|
if (dns_servers_count > 0) {
|
||||||
size_t ret_size = sizeof(char *) * (size_t)dns_servers_count;
|
size_t ret_size = sizeof(char *) * (size_t)dns_servers_count;
|
||||||
*r_dns_servers_array = malloc(ret_size); // freed by the BCL
|
*r_dns_servers_array = malloc(ret_size); // freed by the BCL
|
||||||
|
ERR_FAIL_NULL_MSG(*r_dns_servers_array, "Out of memory.");
|
||||||
memcpy(*r_dns_servers_array, dns_servers, ret_size);
|
memcpy(*r_dns_servers_array, dns_servers, ret_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,8 +85,11 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver
|
||||||
const xatlas::Mesh &output = atlas->meshes[0];
|
const xatlas::Mesh &output = atlas->meshes[0];
|
||||||
|
|
||||||
*r_vertex = (int *)malloc(sizeof(int) * output.vertexCount);
|
*r_vertex = (int *)malloc(sizeof(int) * output.vertexCount);
|
||||||
|
ERR_FAIL_NULL_V_MSG(*r_vertex, false, "Out of memory.");
|
||||||
*r_uv = (float *)malloc(sizeof(float) * output.vertexCount * 2);
|
*r_uv = (float *)malloc(sizeof(float) * output.vertexCount * 2);
|
||||||
|
ERR_FAIL_NULL_V_MSG(*r_uv, false, "Out of memory.");
|
||||||
*r_index = (int *)malloc(sizeof(int) * output.indexCount);
|
*r_index = (int *)malloc(sizeof(int) * output.indexCount);
|
||||||
|
ERR_FAIL_NULL_V_MSG(*r_index, false, "Out of memory.");
|
||||||
|
|
||||||
float max_x = 0;
|
float max_x = 0;
|
||||||
float max_y = 0;
|
float max_y = 0;
|
||||||
|
|
|
@ -172,9 +172,11 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jc
|
||||||
if (p_cmdline) {
|
if (p_cmdline) {
|
||||||
cmdlen = env->GetArrayLength(p_cmdline);
|
cmdlen = env->GetArrayLength(p_cmdline);
|
||||||
if (cmdlen) {
|
if (cmdlen) {
|
||||||
cmdline = (const char **)malloc((cmdlen + 1) * sizeof(const char *));
|
cmdline = (const char **)memalloc((cmdlen + 1) * sizeof(const char *));
|
||||||
|
ERR_FAIL_NULL_MSG(cmdline, "Out of memory.");
|
||||||
cmdline[cmdlen] = NULL;
|
cmdline[cmdlen] = NULL;
|
||||||
j_cmdline = (jstring *)malloc(cmdlen * sizeof(jstring));
|
j_cmdline = (jstring *)memalloc(cmdlen * sizeof(jstring));
|
||||||
|
ERR_FAIL_NULL_MSG(j_cmdline, "Out of memory.");
|
||||||
|
|
||||||
for (int i = 0; i < cmdlen; i++) {
|
for (int i = 0; i < cmdlen; i++) {
|
||||||
|
|
||||||
|
@ -193,9 +195,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jc
|
||||||
for (int i = 0; i < cmdlen; ++i) {
|
for (int i = 0; i < cmdlen; ++i) {
|
||||||
env->ReleaseStringUTFChars(j_cmdline[i], cmdline[i]);
|
env->ReleaseStringUTFChars(j_cmdline[i], cmdline[i]);
|
||||||
}
|
}
|
||||||
free(j_cmdline);
|
memfree(j_cmdline);
|
||||||
}
|
}
|
||||||
free(cmdline);
|
memfree(cmdline);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
|
|
|
@ -115,11 +115,11 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) {
|
||||||
if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) {
|
if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dev_list = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count);
|
dev_list = (PRAWINPUTDEVICELIST)memalloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count);
|
||||||
if (!dev_list) return false;
|
ERR_FAIL_NULL_V_MSG(dev_list, false, "Out of memory.");
|
||||||
|
|
||||||
if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) {
|
if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) {
|
||||||
free(dev_list);
|
memfree(dev_list);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < dev_list_count; i++) {
|
for (unsigned int i = 0; i < dev_list_count; i++) {
|
||||||
|
@ -136,11 +136,11 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) {
|
||||||
(GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) &&
|
(GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) &&
|
||||||
(strstr(dev_name, "IG_") != NULL)) {
|
(strstr(dev_name, "IG_") != NULL)) {
|
||||||
|
|
||||||
free(dev_list);
|
memfree(dev_list);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(dev_list);
|
memfree(dev_list);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,8 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
|
||||||
if (wlen < 0)
|
if (wlen < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wchar_t *wbuf = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
|
wchar_t *wbuf = (wchar_t *)memalloc((len + 1) * sizeof(wchar_t));
|
||||||
|
ERR_FAIL_NULL_MSG(wbuf, "Out of memory.");
|
||||||
MultiByteToWideChar(CP_UTF8, 0, buf, len, wbuf, wlen);
|
MultiByteToWideChar(CP_UTF8, 0, buf, len, wbuf, wlen);
|
||||||
wbuf[wlen] = 0;
|
wbuf[wlen] = 0;
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
|
||||||
else
|
else
|
||||||
wprintf(L"%ls", wbuf);
|
wprintf(L"%ls", wbuf);
|
||||||
|
|
||||||
free(wbuf);
|
memfree(wbuf);
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
Loading…
Reference in a new issue