Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added an arbitrary limit to the number of queued events so it doesn't…
Browse files Browse the repository at this point in the history
… grow unbounded.
  • Loading branch information
slouken committed Jun 11, 2013
1 parent 9a619b0 commit a8f0158
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/events/SDL_events.c
Expand Up @@ -33,6 +33,9 @@
#endif
#include "../video/SDL_sysvideo.h"

/* An arbitrary limit so we don't have unbounded growth */
#define SDL_MAX_QUEUED_EVENTS 65535

/* Public data -- the event filter */
SDL_EventFilter SDL_EventOK = NULL;
void *SDL_EventOKParam;
Expand Down Expand Up @@ -71,6 +74,7 @@ static struct
{
SDL_mutex *lock;
volatile SDL_bool active;
volatile int count;
SDL_EventEntry *head;
SDL_EventEntry *tail;
SDL_EventEntry *free;
Expand Down Expand Up @@ -128,6 +132,7 @@ SDL_StopEventLoop(void)
SDL_free(wmmsg);
wmmsg = next;
}
SDL_EventQ.count = 0;
SDL_EventQ.head = NULL;
SDL_EventQ.tail = NULL;
SDL_EventQ.free = NULL;
Expand Down Expand Up @@ -193,6 +198,11 @@ SDL_AddEvent(SDL_Event * event)
{
SDL_EventEntry *entry;

if (SDL_EventQ.count >= SDL_MAX_QUEUED_EVENTS) {
SDL_SetError("Event queue is full (%d events)", SDL_EventQ.count);
return 0;
}

if (SDL_EventQ.free == NULL) {
entry = (SDL_EventEntry *)SDL_malloc(sizeof(*entry));
if (!entry) {
Expand Down Expand Up @@ -221,6 +231,7 @@ SDL_AddEvent(SDL_Event * event)
entry->prev = NULL;
entry->next = NULL;
}
++SDL_EventQ.count;

return 1;
}
Expand All @@ -247,6 +258,8 @@ SDL_CutEvent(SDL_EventEntry *entry)

entry->next = SDL_EventQ.free;
SDL_EventQ.free = entry;
SDL_assert(SDL_EventQ.count > 0);
--SDL_EventQ.count;
}

/* Lock the event queue, take a peep at it, and unlock it */
Expand Down

0 comments on commit a8f0158

Please sign in to comment.