Replace malloc's with Godot's memalloc macro
This commit is contained in:
parent
01851defb5
commit
838e7d0a8d
6 changed files with 37 additions and 26 deletions
|
@ -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) {
|
||||
|
|
|
@ -415,8 +415,7 @@ GD_PINVOKE_EXPORT int32_t monodroid_get_system_property(const char *p_name, char
|
|||
if (r_value) {
|
||||
if (len >= 0) {
|
||||
*r_value = (char *)malloc(len + 1);
|
||||
if (!*r_value)
|
||||
return -1;
|
||||
ERR_FAIL_NULL_V_MSG(*r_value, -1, "Out of memory.");
|
||||
memcpy(*r_value, prop_value_str, len);
|
||||
(*r_value)[len] = '\0';
|
||||
} else {
|
||||
|
@ -637,6 +636,7 @@ GD_PINVOKE_EXPORT int32_t _monodroid_get_dns_servers(void **r_dns_servers_array)
|
|||
if (dns_servers_count > 0) {
|
||||
size_t ret_size = sizeof(char *) * (size_t)dns_servers_count;
|
||||
*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);
|
||||
}
|
||||
|
||||
|
|
|
@ -161,8 +161,11 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver
|
|||
const xatlas::Mesh &output = atlas->meshes[0];
|
||||
|
||||
*r_vertices = (int *)malloc(sizeof(int) * output.vertexCount);
|
||||
ERR_FAIL_NULL_V_MSG(*r_vertices, false, "Out of memory.");
|
||||
*r_uvs = (float *)malloc(sizeof(float) * output.vertexCount * 2);
|
||||
ERR_FAIL_NULL_V_MSG(*r_uvs, false, "Out of memory.");
|
||||
*r_indices = (int *)malloc(sizeof(int) * output.indexCount);
|
||||
ERR_FAIL_NULL_V_MSG(*r_indices, false, "Out of memory.");
|
||||
|
||||
float max_x = 0.0;
|
||||
float max_y = 0.0;
|
||||
|
|
|
@ -127,9 +127,11 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jc
|
|||
if (p_cmdline) {
|
||||
cmdlen = env->GetArrayLength(p_cmdline);
|
||||
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] = nullptr;
|
||||
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++) {
|
||||
jstring string = (jstring)env->GetObjectArrayElement(p_cmdline, i);
|
||||
|
@ -147,9 +149,9 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jc
|
|||
for (int i = 0; i < cmdlen; ++i) {
|
||||
env->ReleaseStringUTFChars(j_cmdline[i], cmdline[i]);
|
||||
}
|
||||
free(j_cmdline);
|
||||
memfree(j_cmdline);
|
||||
}
|
||||
free(cmdline);
|
||||
memfree(cmdline);
|
||||
}
|
||||
|
||||
if (err != OK) {
|
||||
|
|
|
@ -110,12 +110,11 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) {
|
|||
if (GetRawInputDeviceList(nullptr, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) {
|
||||
return false;
|
||||
}
|
||||
dev_list = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count);
|
||||
if (!dev_list)
|
||||
return false;
|
||||
dev_list = (PRAWINPUTDEVICELIST)memalloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count);
|
||||
ERR_FAIL_NULL_V_MSG(dev_list, false, "Out of memory.");
|
||||
|
||||
if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) {
|
||||
free(dev_list);
|
||||
memfree(dev_list);
|
||||
return false;
|
||||
}
|
||||
for (unsigned int i = 0; i < dev_list_count; i++) {
|
||||
|
@ -130,11 +129,11 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) {
|
|||
(MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == (LONG)p_guid->Data1) &&
|
||||
(GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) &&
|
||||
(strstr(dev_name, "IG_") != nullptr)) {
|
||||
free(dev_list);
|
||||
memfree(dev_list);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
free(dev_list);
|
||||
memfree(dev_list);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
|
|||
if (wlen < 0)
|
||||
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);
|
||||
wbuf[wlen] = 0;
|
||||
|
||||
|
@ -62,7 +63,7 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
|
|||
else
|
||||
wprintf(L"%ls", wbuf);
|
||||
|
||||
free(wbuf);
|
||||
memfree(wbuf);
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
fflush(stdout);
|
||||
|
|
Loading…
Reference in a new issue