Get rid of unchecked calls to malloc
This commit is contained in:
parent
d2048c7ac0
commit
7271e5558c
4 changed files with 8 additions and 2 deletions
|
|
@ -81,6 +81,8 @@ void dthread_send_delta(int pnum, _cmd_id cmd, byte *pbSrc, int dwLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt = static_cast<TMegaPkt *>(std::malloc(dwLen + 20));
|
pkt = static_cast<TMegaPkt *>(std::malloc(dwLen + 20));
|
||||||
|
if (pkt == nullptr)
|
||||||
|
app_fatal("Failed to allocate memory");
|
||||||
pkt->pNext = nullptr;
|
pkt->pNext = nullptr;
|
||||||
pkt->dwSpaceLeft = pnum;
|
pkt->dwSpaceLeft = pnum;
|
||||||
pkt->data[0] = static_cast<byte>(cmd);
|
pkt->data[0] = static_cast<byte>(cmd);
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ void GetNextPacket()
|
||||||
TMegaPkt *result;
|
TMegaPkt *result;
|
||||||
|
|
||||||
sgpCurrPkt = static_cast<TMegaPkt *>(std::malloc(sizeof(TMegaPkt)));
|
sgpCurrPkt = static_cast<TMegaPkt *>(std::malloc(sizeof(TMegaPkt)));
|
||||||
|
if (sgpCurrPkt == nullptr)
|
||||||
|
app_fatal("Failed to allocate memory");
|
||||||
sgpCurrPkt->pNext = nullptr;
|
sgpCurrPkt->pNext = nullptr;
|
||||||
sgpCurrPkt->dwSpaceLeft = sizeof(result->data);
|
sgpCurrPkt->dwSpaceLeft = sizeof(result->data);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ void tmsg_add(byte *pbMsg, uint8_t bLen)
|
||||||
TMsg **tail;
|
TMsg **tail;
|
||||||
|
|
||||||
TMsg *msg = static_cast<TMsg *>(std::malloc(bLen + sizeof(*msg)));
|
TMsg *msg = static_cast<TMsg *>(std::malloc(bLen + sizeof(*msg)));
|
||||||
|
if (msg == nullptr)
|
||||||
|
app_fatal("Failed to allocate memory");
|
||||||
msg->hdr.pNext = nullptr;
|
msg->hdr.pNext = nullptr;
|
||||||
msg->hdr.dwTime = SDL_GetTicks() + gnTickDelay * 10;
|
msg->hdr.dwTime = SDL_GetTicks() + gnTickDelay * 10;
|
||||||
msg->hdr.bLen = bLen;
|
msg->hdr.bLen = bLen;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ SDL_Thread *CreateThread(void (*handler)(), SDL_threadID *threadId)
|
||||||
event_emul *StartEvent()
|
event_emul *StartEvent()
|
||||||
{
|
{
|
||||||
event_emul *ret;
|
event_emul *ret;
|
||||||
ret = (event_emul *)malloc(sizeof(event_emul));
|
ret = new event_emul();
|
||||||
ret->mutex = SDL_CreateMutex();
|
ret->mutex = SDL_CreateMutex();
|
||||||
if (ret->mutex == nullptr) {
|
if (ret->mutex == nullptr) {
|
||||||
ErrSdl();
|
ErrSdl();
|
||||||
|
|
@ -51,7 +51,7 @@ void EndEvent(event_emul *event)
|
||||||
{
|
{
|
||||||
SDL_DestroyCond(event->cond);
|
SDL_DestroyCond(event->cond);
|
||||||
SDL_DestroyMutex(event->mutex);
|
SDL_DestroyMutex(event->mutex);
|
||||||
free(event);
|
delete event;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetEvent(event_emul *e)
|
void SetEvent(event_emul *e)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue